Java OOPs Interview Questions and Answers
Ques 6. What is the 'super' keyword in Java?
The 'super' keyword is used to refer to the superclass, invoking its methods, or accessing its fields. It is often used in the context of method overriding.
Example:
super.display();
Ques 7. What is the purpose of the 'final' keyword?
The 'final' keyword is used to make a variable, method, or class constant and cannot be changed. It also prevents a class from being subclassed.
Example:
final int MAX_VALUE = 100;
Ques 8. What is an abstract class in Java?
An abstract class is a class that cannot be instantiated on its own and may contain abstract methods. It is meant to be subclassed by concrete classes.
Example:
abstract class Shape { /* abstract methods */ }
Ques 9. Explain the difference between an interface and an abstract class.
An interface in Java is a collection of abstract methods, while an abstract class can have both abstract and concrete methods. A class can implement multiple interfaces but can extend only one abstract class.
Ques 10. What is the purpose of the 'this' keyword?
The 'this' keyword is used to refer to the current instance of the class. It is often used to differentiate instance variables from local variables when they have the same name.
Example:
public void setName(String name) { this.name = name; }
Most helpful rated by users: