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

No, because this() and super() must be the first statement in the class constructor.

Example:

  1. public class Test{
  2.     Test()
  3.      {
  4.          super();
  5.          this();
  6.          System.out.println(“Test class object is created”);
  7.      }
  8.      public static void main(String []args){
  9.      Test t = new Test();
  10.      }
  11. }

Output:

Test.java:5: error: call to this must be first statement in constructor