Core Java - Interview Questions and Answers for 'Super' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Super' - 5 question(s) found - Order By Newest

 Q1. Can we use both "this()" and "super()" in a constructor ?Core Java
Ans. No, because both this and super should be the first statement.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops  this   super   constructor     Asked in 1 Companies      intermediate        rare

Try 2 Question(s) Test


 Q2. Why every object constructor automatically call super() in Object before its own constructors?Core Java
Ans. Derived object carries the body of its class as well as the body of the parent class. Its body ( member elements ) is initialized using its own class constructor whereas the body ( member elements ) carried from the parent class are initialized using super class constructor. So In order to initialize the elements of the parent class before its own elements are even initialized, super is called.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   constructor   super   inheritance  object oriented programming (oops)  oops concepts   inheritence     Asked in 1 Companies      intermediate


 Q3. Difference Between this() and super() ?Core Java
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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   class   objects   inheritence   constructor   this   super   this vs super     Asked in 1 Companies

Try 1 Question(s) Test


 Q4. What is "super" used for ?
Ans. Used to access members of the base class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   java keywords   super   basic interview question     Asked in 2 Companies      basic        frequent


 Q5. In a case where there are no instance variables what does the default constructor initialize?Core Java
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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   constructor   object creation   default constructor   super

Try 1 Question(s) Test


 Q6. What is the problem with this code ?

public class Car extends Vehicle{   
   int x;
   
   Car(int y){
      x = 5;
   }
   
   Car(){
      this(5);
      super();
   }
}
Core Java
a. We cannot overload constructors
b. Constructors should have type
c. we should have called super() before this(5)
d. We cannot have both super() and this() in a constructor

Ans.d. We cannot have both super() and this() in a constructor

 Q7. What is the problem with this code ?

public class Car extends Vehicle{
   int x;

   Car(int y){
      x = 5;
   }

   Car(){
      super();
      this.x = 5;
   }
}
Core Java
a. We cannot overload constructors
b. We cannot call super in overloaded constructor
c. we cannot have this and super in constructor
d. There is no problem

Ans.d. There is no problem


Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: