+ 1
why it is printing "class A method"
class A{ static void method(){ System.out.println("Class A method"); } } class B extends A{ static void method(){ System.out.println("Class B method"); } } public class Mcq29{ public static void main(String args[]){ A a = new B(); a.method(); } }
3 Answers
+ 1
Because your method is overlapping each other, if you call class A in your main class you should get A only, take a look at the example
https://code.sololearn.com/cHYuF7yaKSVm/?ref=app
+ 1
john,,i have used static method
+ 1
So static methods are restricted to superclass.