aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding for Static Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding for Static Method" Watch "Overriding for Static Method" New topic
Author

Overriding for Static Method

subhasish nag
Ranch Hand

Joined: Apr 25, 2008
Posts: 101
Refer to the given code
It is an eg of overriding of static methos.Here it is invoking the process method of class A1 & the output comes as "A1" .But as per Overriding rule it always check object type not the refference type. Kindly provide the explanation .

class A1 {
public static void process() {System.out.println("A1");}
}
class B1 extends A1{
public static void process(){System.out.println("B1");}
}
public class Test22{

public static void main(String[] args)
{
A1 a=new B1();
a.process();
}
}


Thanks,<br />Subhasish
Mihai Fonoage
Ranch Hand

Joined: Feb 25, 2006
Posts: 39
Please read Overriding Vs Hiding from JavaRanch FAQ.

Mihai Fonoage
subhasish nag
Ranch Hand

Joined: Apr 25, 2008
Posts: 101
thanks Mihai
suavedeep kaur
Ranch Hand

Joined: Jun 02, 2008
Posts: 36
great page milhai sir thanks, it helped me alot too!!!



Suavedeep kaur
SCJP
 
Don't get me started about those stupid light bulbs.
 
subject: Overriding for Static Method