posted 24 years ago
Which of the following statements are true
1) constructors cannot be overloaded
2) constructors cannot be overridden
3) a constructor can return a primitive or an object reference
4) constructor invocation occurs from the current class up the hierarchy to the ancestor class
I think that 4) is true also.
As I know, class's constructors always call the superclass's constructor (explicitly or implicitly). So, if you have class
Base and a SubBase class extends Base, the code like
SubBase sb = new SubBase(); will invoke super's constructor and then further up. Markus advises to print smth from the constructors to see what is an order of invocations. But, anyway the first line of any constructor should invoke super's constructor (the compiler does it if you missed it). It means that invocation goes up only. Just an example
No one argues about an order of printed lines
1) b method
2) a method
But, the matter is that aMethod invokes bMethod but not conversely.