Why it printed twice constructor invoked
Hi there!
In the main()
method the Dog class is instantiated twice:
Dog fido = new Dog("poodle", false, 5);
Dog nunzio = new Dog("shiba inu", true, 12);
The constructor is invoked for each instantiation, that’s why the line “Constructor invoked!” is printed twice.
1 Like