Can we use both "this()" and "super()" in a constructor ?
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

   



Interview Questions and Answers

 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


Related Questions

  Why every object constructor automatically call super() in Object before its own constructors?
  Difference Between this() and super() ?
  Which of the following is false about Constructors ?
  What is "super" used for ?
  Does a class inherit the constructor of its super class?
  In a case where there are no instance variables what does the default constructor initialize?
 What will the following code print upon executing main method of Main class ?

public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}

public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");

super();
}
}

public class Main {

public static void main(String[] args) {
    DerivedClass derivedClass = new DerivedClass();
}
}

 What will the following code print upon executing main method of Main class ?

public class BaseClass {
BaseClass(int x){
System.out.println("Hello I am in Base Class Constructor");
}
}

public class DerivedClass extends BaseClass{
DerivedClass(){
super(1);
System.out.println("Hello I am in Derived Class Constructor");
}
}

public class Main {

public static void main(String[] args) {
    DerivedClass derivedClass = new DerivedClass();
}
}
 What will the following code print upon executing main method of Main class

public class BaseClass {

BaseClass(){
this(2);
System.out.println("Hello I am in Base Class Constructor");
}

BaseClass(int i){
System.out.println("Hello I am in Base Class int argument Constructor");
}
}

public class DerivedClass extends BaseClass{
DerivedClass(){
super(1);
System.out.println("Hello I am in Derived Class Constructor");
}
}

public class Main {

public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
}



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: