How Static and Constructor will work when class is Extended
public class Main2 extends A { public static void main(String args[]) { } } class A extends B { A() { System.out.println("I am A Constrctor"); } static { System.out.println("I am Static Method"); } { System.out.println("Empty"); } } class B { B() { System.out.println("I am B Constrctor"); } }
OP:I am Static Method
How Static and Constructor will work when class object is Created
public class Main2 extends A { public static void main(String args[]) { A objA = new A(); } } class A extends B { A() { System.out.println("I am A Constrctor"); } static { System.out.println("I am Static Method"); } { System.out.println("Empty"); } } class B { B() { System.out.println("I am B Constrctor"); } }
OP:I am Static Method
I am B Constrctor
Empty
I am A Constrctor