GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract Method" Watch "Abstract Method" New topic
Author

Abstract Method

agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
Hai,
Why abstract Methods Can't Be Declared As static?
Plz Clear My Doubt..
Thanks In Advance


#######################################################3
Agrah Upadhyay
3rd Year
B.T.ech
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

In general, the keyword "abstract" defers implementation to a subclass. However, static methods cannot be overridden.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Any method that is defined to be abstract has to belong to an abstract class.An abstract class cannot be instantiated but it can be declared.

Abstract classes exist to support the concept of inheritance/generalization.
And making static methods abstract will not help since static methods are not overriden by sub classes, but hidden.


/** Code speaks louder than words */
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
Thank U Weber But Can't U Be more Clear In Ur Xplanation?

##########################33333
Agrah Upadhyay
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Hi,

Besides this if you still declare an Abstract method as static...consider the following situation


then this is the output
----------------------
Derieved.java:3: illegal combination of modifiers: abstract and static
abstract static void method();
^
Derieved.java:7: method() in Derieved cannot override method() in Base; overridden method is static
void method()
^
2 errors
------------------------

hope this helps you

Sandy


Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Amit Goel
Ranch Hand

Joined: Dec 07, 2000
Posts: 50
abstract methods are meant to be overridden as they don't have a body and the implementation is expected in a subclass..

and static methods cannot be overridden as they are class methods and not instance methods. means that they ar shared across objects .

so abstract and static are against each other and can't co-exist

Thanx


Amit<br /> <br />The Less I have, The more I gain..Off the Beaten Path, I Reign.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by agrah upadhyay:
Thank U Weber But Can't U Be more Clear In Ur Xplanation?


Looks like Amit beat me to it.
[ September 16, 2005: Message edited by: marc weber ]
chinni Reddy
Greenhorn

Joined: Aug 16, 2005
Posts: 11
this link gives good info about the java modifiers
http://www.uni-bonn.de/~manfear/javamodifiers.php
 
GeeCON Prague 2014
 
subject: Abstract Method