Given:
and
and
What is the result?
Given:
and
and
What is the result?
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'.
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
D correct. Tested
Tested: D.
Answer: D
D is correct
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.
instance method cannot override the static method from Super
D not A but the explanation is the same
A is correct , static methods are class bound hence are not inherited