super() call: ============= package JavaIO.AIT; class Class1{ // parent class Class1(){ System.out.println("This is the Parent Class Constructor without parameters."); } } class Class2 extends Class1{ // child class Class2(){ System.out.println("This is the Child Class constructor without parameters."); } } public class MainClass { public static void main(String[] args) { Class2 c2 = new Class2(); } } ===================================================== package JavaIO.AIT; class Class1{ // parent class Class1(int x) { System.out.println("This is the parent class constructor with parameters."); System.out.println("x = "+x); } } class Class2 extends Class1{ Class2(int x){ super(x); System.out.println("This is the Child Class constructor without parameters."); } } public class MainClass { public static void main(String[] args) { // Class2 c2 = new Class2(120); Class2 c3 = new Class2(240); } } ======================================================= package JavaIO.AIT; class A{ // how many constructors? ans: 1 // when there is no constructor in a class, JVM automatically add a constructor. } class B extends A{ B(){ System.out.println("This is Child class constructor without parameters"); } B(int x) { System.out.println("This is the Child Class constructor with parameters."); } } public class MainClass { public static void main(String[] args) { // B bref = new B(); B bref1 = new B(200); } } ======================================================== this() call: ============ ==> this() call can use to call the same class constructor. ==> as like super() call, the this() call also be the first statement in the constructor. ==> If a constructor with this() call, we cannot able to add/write super() call. ==> If a constructor with super() call, we cannot able to write this() call within the same constructor. package JavaAIT.IO; class A{ A(){ System.out.println("This is the Parent Class constructor with 0 parameters."); } } class B extends A{ B(){ this(100); System.out.println("This is the Child Class Constructor with 0 parameters."); } B(int x){ System.out.println("This is the Child Class Constructor with parameter."); } } public class MainClass { public static void main(String[] args) { B bref = new B(); } }