0

i didn't understant when i excuteed the program below , how the " New A " appeared :p ? and thank you <3

class A { public A() { System.out.println("New A"); } } class B extends A { public B() { System.out.println("New B"); } } class Program { public static void main(String[ ] args) { B obj = new B(); } } }

6th Aug 2017, 3:21 AM
Khouloud ZOUAGHI
Khouloud ZOUAGHI - avatar
1 Answer
+ 6
When an object of a derived class is created, the constructor of the base class is called first, before calling the constructor of the derived class. Output: New A New B
6th Aug 2017, 4:06 AM
Hatsy Rei
Hatsy Rei - avatar