• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

static method

 
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if there is a superclass that has public static method m()...and there is subclass that extends that Superclass and it is legal to declare to private static method m()

i just want to know if this happens because the static method cant be overridden but redefined in the subclass and none of the overriding rules apply to static methods...

please Confirm

 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raju Champaklal wrote:if there is a superclass that has public static method m()...and there is subclass that extends that Superclass and it is legal to declare to private static method m()


This isn't true. Have a look at OverridingVsHiding FAQ
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

please Confirm



Confirm what ?

You can indeed define a method with the same signature, but it would be hidden, not overridden.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i pasted that code in Netbeans..
Netbeans tells warning in the code :


warning message :


m() in And2 cannot oveeride m() in And; attempting to assign weaker access privileges; was public



you tried to override And's method with And2's method..
And2's method has weaker access (private privileges)..

if you tried to replace the private to public, its mean that you "hiding" the And's method :


i've changed the code as below :


the result is :


And2's m method is executed

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

m() in And2 cannot oveeride m() in And; attempting to assign weaker access privileges; was public



Since static methods cannot be over-ridden(and no overriding rules are applied to them), why would compiler even complain about it?


Regards,
Chintan.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually static methods cant be overridden but can be redefined...and the rules for redefining are the same as overridden...its just that actually the polymorphism cant be used with static methods...thats all that is
 
Chintan B Shah
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it..Thanks Raju.

Wow!! I am learning some great new stuff here...not taught in class. Javaranch rocks!!!

Regards,
Chintan.
 
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will learn a lot of things here that are not taught in the class .

You can go through this stuff too for more clarification. Sorry for bumping the post ..
 
Chintan B Shah
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sudipto.

Regards,
Chintan
reply
    Bookmark Topic Watch Topic
  • New Topic