Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If we override static method then how many copies are created of static method?

 
anmol meghadambar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we override static method then how many copies are created of static method?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

static method cant be override, mean while we can hide super class version by declaring the same method in subclass. for more detail, search here...
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please refer http://www.coderanch.com/how-to/java/Java-FAQ
 
anmol meghadambar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Seetharaman Venkatasamy and gurpeet singh for replay me.....

yes we cant override static method i got the answer but we can redefine into sub class with same signature and it will create two copies of static methods

code:-
class SuperClass
{

public static void get()
{
System.out.println("In Super Class");

}

}
public class SubClass extends SuperClass
{
public static void get()
{
System.out.println("In Sub Class");

}
public static void main(String a[])
{
SuperClass superobj=new SuperClass();
SubClass subobj=new SubClass();

superobj=new SubClass();
superobj.get();

subobj.get();


}
}
/*output:-
In Super Class
In Sub Class*/

 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes we cant override static method i got the answer but we can redefine into sub class with same signature and it will create two copies of static methods


No these are 2 different static methods (albeit having the same signature), not copies.
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm also curious what you mean by "two copies" when referring to methods?
 
raju salla
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
We can override static methods in java. Static method can be overriden to static only. We can't override static method to not-static method and also we cannot override non-static method to static method in java.


Thank you.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can override static methods in java.


Incorrect. Static methods are not overridden simply because they belong to the class rather than an instance of that class.

Also, in the code snippet above, you should access the static methods the correct way - NameOfClass.nameOfStaticMethod
 
anmol meghadambar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Kumar M K wrote:
yes we cant override static method i got the answer but we can redefine into sub class with same signature and it will create two copies of static methods


No these are 2 different static methods (albeit having the same signature), not copies.



yes I got the answer thank you Praveen.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic