This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Method

 
agrah upadhyay
Ranch Hand
Posts: 579
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, the keyword "abstract" defers implementation to a subclass. However, static methods cannot be overridden.
 
Shivani Chandna
Ranch Hand
Posts: 380
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
agrah upadhyay
Ranch Hand
Posts: 579
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank U Weber But Can't U Be more Clear In Ur Xplanation?

##########################33333
Agrah Upadhyay
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amit Goel
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this link gives good info about the java modifiers
http://www.uni-bonn.de/~manfear/javamodifiers.php
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic