• Post Reply Bookmark Topic Watch Topic
  • New Topic

abstract class  RSS feed

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no abstract method can be defined as an abstract class ? weird ?

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why so weird? what if you just want to declare some protected instance vars ?
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edward Chen wrote:no abstract method can be defined as an abstract class ? weird ?

An abstract method must be in an abstract class. But an abstract class can be without abstract method. May be the language wanted something between- Interface and a concrete class. So that programmers need not keep implementing all the methods as required by Interface.

This is the one drawback of an Interface- You would have to implement the methods whenever the class implements the interface- No matter even if the implemented code is same over different implementations. The abstract class would come in handy in such situations (but we would not be able to extend other classes ) Scala has something called Traits which overcome this problem of Interfaces .
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!