Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we override static method then how many copies are created of static method?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please refer https://coderanch.com/how-to/java/Java-FAQ
 
anmol meghadambar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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*/

 
Ranch Hand
Posts: 256
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 9031
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm also curious what you mean by "two copies" when referring to methods?
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic