Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overriding Vs Hiding Static Methods

Status
Not open for further replies.

bsuribabu

Programmer
Apr 4, 2002
25
0
0
IN
Hi all,

As all u know that we cannot override static methods
in derived class . But we can hide it with same signature of static methods .

I dont understand what is the basic diff between Overriding methods and Method hiding.


Suri

 
The difference manifests itself during polymorphism:
Code:
class A{
	public static String speak(){return "A.speak";}
	public String talk(){return "A.talk"; }
}
class B extends A{
	public static String speak(){return "B.speak";}
	public String talk(){return "B.talk"; }
}

// then in your main()
		 // employ polymorphism
		 A mya = new B();
		 System.out.println( mya.speak());	// static is still A
		 System.out.println( mya.talk());	// virtual function is B

The output is:
A.speak
B.talk

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top