How does inheritance and polymorphism work with static methods? Could someone explain what the proper output is supposed to be here and how it was derived?
class A { public static int get() { return 17; } } class B extends A { public static int get() { return 42; } } Main A x = new B(); x.get(); The error message,
The static method get() from the type A should be accessed in a static way
I think I know how to access to it in a static way but this is a question from class and its sort of implied that one or the other values would be returned
In our program, we have the class definitions:
class A { public static int get() { return 17; } } class B extends A { public static int get() { return 42; } } and somewhere else we declare A x = new B();
What number will the call x.get() return?
A x = new B();will return 17 onx.get();butB y = new B();will return 42 ony.get();