Can you use this() and super() both in a constructor?

DWQA QuestionsCategory: JavaCan you use this() and super() both in a constructor?
satya asked 10 months ago

Can you use this() and super() both in a constructor?

1 Answers
Editor Staff answered 10 months ago

No, because this() and super() must be the first statement in the class constructor.
Example:
public class Test{
Test()
{
super();
this();
System.out.println(“Test class object is created”);
}
public static void main(String []args){
Test t = new Test();
}
}
Output:
Test.java:5: error: call to this must be first statement in constructor