Answer Key
1. What is an object in Java?
Answer: B) An instance of a class
2. What is a class in Java?
Answer: A) A blueprint for creating objects
3. What does encapsulation mean in Java?
Answer: A) Hiding the internal state of an object
4. What is inheritance in Java?
Answer: A) A way to define new classes based on existing ones
5. What is a constructor in Java?
Answer: A) A method that initializes an object
6. What is method overloading?
Answer: A) Defining multiple methods with the same name but different parameters
7. What is method overriding?
Answer: A) Defining a method in a subclass that has the same name and parameters as a
method in the parent class
8. What is the purpose of the super keyword in Java?
Answer: A) To refer to the parent class
9. What is polymorphism in Java?
Answer: A) The ability to present the same interface for different underlying data types
10. What is an interface in Java?
Answer: A) A contract that classes can implement
11. What is an abstract class in Java?
Answer: A) A class that cannot be instantiated and may contain abstract methods
12. What does the this keyword refer to in Java?
Answer: A) The current object instance
13. What is a static method in Java?
Answer: A) A method that belongs to the class rather than any instance
14. What is the difference between == and .equals() in Java?
Answer: A) == checks for reference equality, while .equals() checks for value equality
15. What is a package in Java?
Answer: A) A namespace that organizes a set of related classes and interfaces
Simple Java Programs Questions
16. What will be printed by this code?
Answer: A) Apple Banana Cherry
17. What is the output of the following code?
Answer: B) Odd
18. What will be printed by the following code?
Answer: B) JAVA
19. What is the output of this program?
Answer: C) 8
20. What will this code output?
Answer: B) 20