Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding for Static Method

 
subhasish nag
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
}
 
Mihai Fonoage
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read Overriding Vs Hiding from JavaRanch FAQ.

Mihai Fonoage
 
subhasish nag
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Mihai
 
suavedeep kaur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great page milhai sir thanks, it helped me alot too!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic