aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Statics Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Statics" Watch "Statics" New topic
Author

Statics

Arun Kumar Gaddam
Ranch Hand

Joined: May 05, 2007
Posts: 58
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
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

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
polymorphism at runtime is only for instance method?

Yes.
See also this: Polymorphism


Bu.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Statics
 
Similar Threads
Static methods and inheritance.
referencing to static from non-static context
Accessing Static Members
Regarding static
Overriding static methods