• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to make a java method derivable but have implementation?  RSS feed

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like

public abstract void CreateDemoPanel()
{
}

But this cannot be done, an abstract class cannot have implementation, I want the derived classes to use the base class method
whenever the class doesn't provide/override one.
Thanks
Jack
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Luk wrote:But this cannot be done, an abstract class cannot have implementation, I want the derived classes to use the base class method
whenever the class doesn't provide/override one.

So: don't make the method abstract.

Winston
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Luk wrote:... an abstract class cannot have implementation

You mean: An abstrace method cannot have an implementation.

Abstract classes can certainly contain methods with an implementation.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!