This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding for Static Method" Watch "Overriding for Static Method" New topic

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();

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
It is sorta covered in the JavaRanch Style Guide.
subject: Overriding for Static Method
Similar Threads
Qs about toString()
Method Invocation
Overloaded Methods in Java are early binded or late binded
help needed on Inner classes program