aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static method" Watch "static method" New topic
Author

static method

Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
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



scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3167
    
  47

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


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

please Confirm


Confirm what ?

You can indeed define a method with the same signature, but it would be hidden, not overridden.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

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


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Chintan B Shah
Ranch Hand

Joined: Sep 23, 2008
Posts: 83
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.


SCJA 1.0
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
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

Joined: Sep 23, 2008
Posts: 83
Got it..Thanks Raju.

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

Regards,
Chintan.
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

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 ..


Regards, Sud.
SCJP 5 ScjpFAQ JLS
Chintan B Shah
Ranch Hand

Joined: Sep 23, 2008
Posts: 83
Thanks Sudipto.

Regards,
Chintan
 
jQuery in Action, 2nd edition
 
subject: static method