Java - Interview Questions and Answers on "Super" keyword

Q1.  What is "super" used for ?

Ans. Used to access members of the base class.

Q2.  Can we use both "this" and "super" in a constructor ?

Ans. No, because both this and super should be the first statement.

Q3.  Difference Between this() and super() ?


1.this is a reference to the current object in which this keyword is used whereas super is a reference used to access members specific to the parent Class. 

2.this is primarily used for accessing member variables if local variables have same name, for constructor chaining and for passing itself to some method whereas super is primarily used to initialize base class members within derived class constructor. 

Q4.  In a case where there are no instance variables what does the default constructor initialize?

Ans. Java expects the superclass ( Object Class ) constructor to be called while creation of any object. So super constructor is called in case there are no instance variables to initialize.