Which is the Best Java Web Framework ?

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() ?

Ans. 

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.   

Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.