Chapter 4 Revel Questions and Answers
with Complete Solutions
What is the purpose of a constructor in Java?
✔✔ A constructor initializes a new object of a class.
How do you call a method from another method within the same class?
✔✔ By using the method name directly or using the **this** keyword.
What happens if you do not define a constructor in a class?
✔✔ Java provides a default constructor automatically.
What is the difference between an instance variable and a local variable?
✔✔ An instance variable belongs to an object and persists as long as the object exists, while a
local variable exists only within a method and is destroyed once the method finishes execution.
How do you create an object of a class in Java?
✔✔ By using the **new** keyword followed by the class constructor.
1
, What does the **this** keyword represent in Java?
✔✔ It represents the current instance of the class.
What happens when a method is declared as **static**?
✔✔ It belongs to the class rather than any instance of the class.
What is the purpose of method overloading?
✔✔ It allows multiple methods to have the same name but different parameter lists.
How can a method in a subclass override a method in its superclass?
✔✔ By defining a method with the same name, return type, and parameters as the method in the
superclass.
What keyword is used to call a constructor of the superclass?
✔✔ **super**
What is an accessor method?
2