0% found this document useful (0 votes)
5 views

Answer Key for Java

The document contains an answer key for Java-related questions, covering fundamental concepts such as objects, classes, encapsulation, inheritance, and polymorphism. It also includes questions about simple Java programs and their expected outputs. Each question is paired with its correct answer, providing a quick reference for Java programming concepts.

Uploaded by

louielaolong9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Answer Key for Java

The document contains an answer key for Java-related questions, covering fundamental concepts such as objects, classes, encapsulation, inheritance, and polymorphism. It also includes questions about simple Java programs and their expected outputs. Each question is paired with its correct answer, providing a quick reference for Java programming concepts.

Uploaded by

louielaolong9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like