Given the classes: What is the result?
A.
unknown Harry
B.
An exception is thrown at runtime.
C.
Compilation fails.
D.
john unknown
E.
John Harry
F.
unknown unknown
Given the classes: What is the result?
A.
unknown Harry
B.
An exception is thrown at runtime.
C.
Compilation fails.
D.
john unknown
E.
John Harry
F.
unknown unknown
a. unknown Harry
C – variable name is the same but cannot be. Name was declare in Pupil.
tested it, correct answer is F.
the modifier of name of Pupil is package private.
during compilation, compiler retrieved the p1.name of Pupil instance in that p1 is the Pupil type, the member method getName is virtual and runtime would dynamicaly link it to the correct Object method, here is the Pupil’s getName.
during compilation, compiler retrieved the p1.name of Pupil instance in that p1 is the Pupil type, the member method getName is virtual and runtime would dynamicaly link it to the correct Object method, here is the Harry’s getName.
A:unknownHarry!! (tested)
+1. A, tested!