Chapter one: introduction
1. Which of the following is a programming paradigm?
o A) Object-Oriented
o B) Structured
o C) Functional
o D) All of the above
Answer: D) All of the above
2. What is a key principle of Object-Oriented Programming?
o A) Polymorphism
o B) Iteration
o C) Compilation
o D) None of the above
Answer: A) Polymorphism
3. Java Applets are primarily used for:
o A) Desktop applications
o B) Web-based applications
o C) Command-line tools
o D) None of the above
Answer: B) Web-based applications
4. The process of converting Java code into bytecode is called:
o A) Interpretation
o B) Compilation
o C) Execution
o D) Debugging
Answer: B) Compilation
Chapter Two: Basics of Java Programming
6. Which of the following is a valid variable type in Java?
o A) int
o B) string
o C) float32
o D) number
Answer: A) int
7. What does the following code declare? String name;
o A) An integer variable
o B) A floating-point variable
o C) A string variable
o D) A character variable
Answer: C) A string variable
8. What is type casting?
o A) Converting a variable to a different type
o B) Creating a new type
o C) Changing the name of a type
o D) None of the above
Answer: A) Converting a variable to a different type
9. Which statement is used for decision-making in Java?
o A) for
o B) if
o C) while
o D) do while
Answer: B) if
10. Which loop will execute at least once?
o A) for loop
o B) while loop
o C) do-while loop
o D) None of the above
Answer: C) do-while loop
11. What is an array?
o A) A single variable
o B) A collection of variables of the same type
o C) A method
o D) A class
Answer: B) A collection of variables of the same type
Chapter Three: Objects and Classes
13. What is an object in OOP?
o A) A data structure
o B) An instance of a class
o C) A method
o D) A variable type
Answer: B) An instance of a class
14. What is the purpose of a constructor?
o A) To define a class
o B) To create an instance of a class
o C) To initialize object variables
o D) Both B and C
Answer: D) Both B and C
15. What do you call the variables defined in a class?
o A) Methods
o B) Object variables
o C) Functions
o D) None of the above
Answer: B) Object variables
16. What is encapsulation?
o A) Hiding the implementation details of a class
o B) Sharing data between classes
o C) Creating multiple instances of a class
o D) None of the above
Answer: A) Hiding the implementation details of a class
17. What keyword is used to define a class in Java?
o A) func
o B) class
o C) object
o D) define
Answer: B) class
Chapter Four: OOP Concepts
18. Inheritance allows a class to:
o A) Use another class's methods and variables
o B) Create new classes
o C) Hide data
o D) None of the above
Answer: A) Use another class's methods and variables
19. What is method overloading?
o A) Defining the same method with different parameters
o B) Overriding a method in a subclass
o C) Creating multiple classes
o D) None of the above
Answer: A) Defining the same method with different parameters
20. Which of the following is a feature of polymorphism?
o A) One interface, multiple implementations
o B) One class, multiple instances
o C) Multiple classes, one implementation
o D) None of the above
Answer: A) One interface, multiple implementations
21. What is an abstract class?
o A) A class that cannot be instantiated
o B) A class that implements interfaces
o C) A class with only static methods
o D) None of the above
Answer: A) A class that cannot be instantiated
22. What is the primary purpose of interfaces?
o A) To support multiple inheritance
o B) To store data
o C) To create objects
o D) None of the above
Answer: A)
Chapter Five: Exception Handling
23. What is the main purpose of exception handling?
o A) To improve code readability
o B) To handle runtime errors
o C) To compile code
o D) None of the above
Answer: B) To handle runtime errors
24. Which of the following is a keyword used for exception handling?
o A) try
o B) catch
o C) finally
o D) All of the above
Answer: D) All of the above
25. What does the finally block do?
o A) Executes code regardless of an exception
o B) Only executes if an exception occurs
o C) Is optional in exception handling
o D) None of the above
Answer: A) Executes code regardless of an exception
Chapter Six: GUI & Java Applets
26. What does GUI stand for?
o A) Graphical User Interface
o B) General User Interface
o C) Graphical Universal Interface
o D) None of the above
Answer: A) Graphical User Interface
27. Java Applets are:
o A) Stand-alone applications
o B) Designed to run on web browsers
o C) Used for server-side applications
o D) None of the above
Answer: B) Designed to run on web browsers
28. Which of the following is a component of a GUI?
o A) Button
o B) Text Field
o C) Label
o D) All of the above
Answer: D) All of the above
29. How do Java Applets differ from Java Applications?
o A) Applets are run in a browser, applications run stand-alone
o B) Applets have no main method, applications do
o C) Applets are less secure than applications
o D) Both A and B
Answer: D) Both A and B
30. What is the main method's signature in a Java application?
o A) public void main(String[] args)
o B) public static void main(String[] args)
o C) static void main(String args)
o D) void main(String[] args)
Answer: B) public static void main(String[] args)
Additional Questions
31. Which of the following is NOT a Java data type?
o A) int
o B) float
o C) char
o D) double precision
Answer: D) double precision
32. What is the output of System.out.println(2 + 3 + "5");?
o A) 25
o B) 55
o C) 7
o D) 23
Answer: B) 55
33. How do you declare a constant in Java?
o A) const double PI = 3.14;
o B) final double PI = 3.14;
o C) double PI = 3.14;
o D) static double PI = 3.14;
Answer: B) final double PI = 3.14;
34. What is the default value of a boolean variable in Java?
o A) true
o B) false
o C) 0
o D) null
Answer: B) false
35. Which of the following is a valid way to create an array in Java?
o A) int[] arr = new int[5];
o B) int arr = new int[5];
o C) int arr[] = int[5];
o D) int arr[5];
Answer: A) int[] arr = new int[5];
36. What is the output of the following code? System.out.println(10 % 3);
o A) 1
o B) 3
o C) 0
o D) 10
Answer: A) 1
37. What does this keyword refer to in Java?
o A) The current class
o B) The current instance of a class
o C) A static method
o D) None of the above
Answer: B) The current instance of a class
38. What is the purpose of the super keyword?
o A) To call a superclass constructor
o B) To access superclass methods
o C) To access superclass variables
o D) All of the above
Answer: D) All of the above
39. Which exception is thrown when dividing by zero in Java?
o A) ArithmeticException
o B) NullPointerException
o C) IndexOutOfBoundsException
o D) IOException
Answer: A) ArithmeticException
40. What is the correct way to handle exceptions?
o A) Using try-catch blocks
o B) Using if statements
o C) Ignoring the exception
o D) None of the above
Answer: A) Using try-catch blocks
41. Which method is used to start a thread in Java?
o A) run()
o B) start()
o C) execute()
o D) begin()
Answer: B) start()
42. Which of the following is NOT an access modifier in Java?
o A) public
o B) private
o C) protected
o D) friendly
Answer: D) friendly
43. What will be the output of System.out.println(1 + "2" + 3);?
o A) 123
o B) 6
o C) 15
o D) 1 + 2 + 3
Answer: A) 123
44. Which of the following is a feature of Java?
o A) Platform independence
o B) Automatic garbage collection
o C) Object-oriented
o D) All of the above
Answer: D) All of the above
45. What is the primary role of the JVM?
o A) To compile Java code
o B) To execute Java bytecode
o C) To convert Java into other languages
o D) None of the above
Answer: B) To execute Java bytecode
46. What does the static keyword signify?
o A) A variable that cannot change
o B) A method that belongs to the class rather than instances
o C) A class that cannot be instantiated
o D) None of the above
Answer: B) A method that belongs to the class rather than instances
47. Which of the following collections allows duplicates?
o A) Set
o B) List
o C) Map
o D) None of the above
Answer: B) List
48. What is the purpose of the break statement?
o A) To terminate a loop
o B) To skip the current iteration
o C) To exit a method
o D) None of the above
Answer: A) To terminate a loop
49. Which of the following can be an interface in Java?
o A) A class
o B) A method
o C) A collection
o D) A blueprint for classes
Answer: D) A blueprint for classes
50. What does StringBuilder do in Java?
o A) Creates immutable strings
o B) Creates mutable strings
o C) Implements string comparison
o D) None of the above
Answer: B) Creates mutable strings
51. What is the use of the final keyword?
o A) To declare constants
o B) To prevent method overriding
o C) To prevent inheritance
o D) All of the above
Answer: D) All of the above
52. Which of the following is a valid way to instantiate an object?
o A) ClassName obj = new ClassName();
o B) ClassName obj;
o C) new ClassName obj;
o D) None of the above
Answer: A) ClassName obj = new ClassName();
53. What is method overriding?
o A) Creating a method with the same name in the same class
o B) Changing the implementation of a method in a subclass
o C) Creating multiple methods with the same name in a class
o D) None of the above
Answer: B) Changing the implementation of a method in a subclass
54. Which of the following statements is true about Java?
o A) Java is platform-dependent.
o B) Java uses pointers.
o C) Java is purely object-oriented.
o D) Java supports multiple inheritance through interfaces.
Answer: D) Java supports multiple inheritance through interfaces.
55. What is the main purpose of the main method in Java?
o A) To define the starting point of a Java application
o B) To create objects
o C) To execute threads
o D) None of the above
Answer: A) To define the starting point of a Java application
56. Which data structure uses a key-value pair?
o A) List
o B) Set
o C) Map
o D) Array
Answer: C) Map
57. What is the result of 5 == 5 in Java?
o A) true
o B) false
o C) 5
o D) None of the above
Answer: A) true
58. Which loop is best for iterating a known number of times?
o A) for loop
o B) while loop
o C) do-while loop
o D) None of the above
Answer: A) for loop
59. What does the instanceof operator do?
o A) Checks if an object is an instance of a class
o B) Creates an instance of a class
o C) Compares two objects
o D) None of the above
Answer: A) Checks if an object is an instance of a class
60. Which of the following is an example of a checked exception?
o A) NullPointerException
o B) IOException
o C) ArithmeticException
o D) RuntimeException
Answer: B) IOException