File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes If we override static method then how many copies are created of 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 "If we override static method then how many copies are created of static method?" Watch "If we override static method then how many copies are created of static method?" New topic
Author

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

anmol meghadambar
Greenhorn

Joined: May 24, 2012
Posts: 4
If we override static method then how many copies are created of static method?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Apr 04, 2012
Posts: 924
    
    1

please refer http://www.coderanch.com/how-to/java/Java-FAQ
anmol meghadambar
Greenhorn

Joined: May 24, 2012
Posts: 4
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

Joined: Jul 03, 2011
Posts: 256
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

Joined: Oct 14, 2002
Posts: 8803
    
    5
I'm also curious what you mean by "two copies" when referring to methods?


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
raju salla
Greenhorn

Joined: Jan 05, 2012
Posts: 18
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

Joined: Nov 09, 2011
Posts: 1012
    
    5

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

Joined: May 24, 2012
Posts: 4
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.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: If we override static method then how many copies are created of static method?
 
Similar Threads
Converting String to Color
Regarding Signature of the main method
Can't get the result of factorial method
javadoc format colors
Static method overridden!! need felp!!