Sample1

See the code below:

public class A { public A() { System.out.println("in the constructor of A"); methodA(); } public void methodA() { System.out.println("MethodA of A"); }}

public class B extends A{ public B(){ System.out.println("in the constructor of B"); } public void methodA(){ System.out.println("methodA of B"); }}

public static void main(String[] args) { A a = new B();}

Output?

Answer:

in the constructor of A

methodA of B

in the constructor of B

Now, make change in class A, change the methodA from public to private, what will be the output?

Answer:

in the constructor of A

methodA of A

in the constructor of B