class A{ static void get1(){ System.out.println("A s get1"); } void get2(){ System.out.println("A s get2"); } void get(){ get1(); get2(); } }
public class Whiz35 extends A{ static void get1(){ System.out.println("Whiz s get1"); } void get2(){ System.out.println("Whiz s get2"); }
public static void main(String... args){ new Whiz35().get(); } }
How could non static classes would be called from non static i.e get()???
dhwani mathur
Ranch Hand
Joined: May 08, 2007
Posts: 621
posted
0
Well!! May be i am not sure with this what i can say on this is
Whiz35 extends class A so it can inherit all methods of class A And in the main you are creating an instance using that you are calling the method get() inherited from class A
public static void main(String... args){ new Whiz35().get(); }
Generally In main we create object of class then using dot operator we call methods (not compulsory they must be static) Here above you are using instance of class to call the method!!
i hope it helps!!!
Jianghu Li
Greenhorn
Joined: Sep 01, 2007
Posts: 13
posted
0
Output is:
why not "Whiz s get1 Whiz s get2"? polymorphism at runtime is only for instance method?
Burkhard Hassel
Ranch Hand
Joined: Aug 25, 2006
Posts: 1274
posted
0
polymorphism at runtime is only for instance method?