Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 45

Given:

and

and

What is the result?

    Correct Answer: D

    Static methods in Java are not overridden but hidden. When a static method is called on an object, the method that executes is determined at compile time by the type of the reference. In this case, 's' is a reference of type 'Super', so 'Super's static method 'greeting()' is called, which returns 'Good Night'. However, instance methods like 'name()' are overridden based on the actual object's class, which in this case is 'Sub'. Therefore, 'Sub's 'name()' method is called, returning 'Potter'. The result is 'Good Night, Potter'.

Discussion
d7bb0b2Option: D

D is correct, static method not override, only instance method because has the same signature and name is override. When uses a Super class variable and access to static method is the methods of that class

[Removed]Option: D

D correct. Tested

OmnisumemOption: D

Tested: D.

tmuralimanoharOption: D

Answer: D

StavokOption: D

D is correct

Mukes877Option: D

D is correct Because instance method cannot override the static method from Super And Potter will be printed because other method will be overriden by instance method So Good night, Potter will printed.

RP384Option: D

instance method cannot override the static method from Super

TADIEWAOption: D

D not A but the explanation is the same

TADIEWAOption: A

A is correct , static methods are class bound hence are not inherited