Java Magazine, Sept/Oct 2018
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2018 82 fix this tion here is that a single call to new might result in many constructors being executed but those executions are all working to initialize a single object Therefore one of the following three situations will occur in the very first line of any constructor and that situation determines execution flow If the first line is an explicit call to another overloaded constructor in the same class written as this execution sidesteps to that constructor If the first line is an explicit call to a superclass constructor written as super execution moves up to that superclass constructor If the first line is neither this nor super a compiler generated call to the zeroargument constructor in the parent class is invoked In the NamedBuffer class theres no explicit call to this or super Therefore the third situation described above applies The resulting call to the zero argument constructor is successful because such a constructor is defined explicitly in this case in the parent class Buffer Because of this you can determine that the NamedBuffer class compiles successfully and option B is incorrect The constructor of the HugeNamedBuffer class also follows the third situation described above that is neither this nor super is mentioned Therefore just as with the NamedBuffer the compiler will insert super implicitly This results in generated bytecode equivalent to this source code public HugeNamedBuffer String name super added by compiler this name name this capacity 1000 Of course the parent class NamedBuffer has one explicit constructor in the source code The existence of that constructor prevents the compiler from generating a default so this is the only constructor available for initialization of any NamedBuffer or the NamedBuffer elements of
You must have JavaScript enabled to view digital editions.