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(); } } }
1 Odpowiedź
+ 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