Can we use both "this()" and "super()" in a constructor ?
Questions
Search
List By Company
List By Topic
Legacy
Tests
Repository
DashBoard
Java
Java 8
Java 7
Java Abbreviations
OCJP / SCJP
Class List
New in Java 8
Java Exceptions
Spring Exceptions
Java Enums
Java 8 Lambda
Java 8 java.time
Big Data
Best Of Java
Discussion
Search
Subscribe
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
Search
Submit Question
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
Correction
Duplicate of Another Question
Company where this question was Asked
Suggestion
Try 2 Question(s) Test
What is the problem with this code ?
public class Car extends Vehicle{
int x;
Car(int y){
x = 5;
}
Car(){
this(5);
super();
}
}
We cannot overload constructors
Constructors should have type
we should have called super() before this(5)
We cannot have both super() and this() in a constructor
What is the problem with this code ?
public class Car extends Vehicle{
int x;
Car(int y){
x = 5;
}
Car(){
super();
this.x = 5;
}
}
We cannot overload constructors
We cannot call super in overloaded constructor
we cannot have this and super in constructor
There is no problem
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: