Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Abstract class does not need to implement interface methods?

 
Ranch Hand
Posts: 153
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quote from a book:

When an interface inherits other interfaces, any class that implements that interface must implement all of the methods declared by that interface and the inherited interfaces. For example, if a class implements the ProductDAO class, it must implement all of the methods defined by the ProductReader and ProductWriter classes. If it doesn't, the class must be declared as abstract so that no objects can be created from it.



I don't understand that last sentence. Why does it make it ok for a class to implement an interface but not its methods when it's declared abstract? What does the inability of creating objects from this class have to do with implementing methods from its implemented interfaces?
 
Ranch Hand
Posts: 417
Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means the concrete classes extending your abstract class will have to implement the interface methods if they aren't already implemented in the abstract class. You can implement some of the interface methods in your abstract classes, the rest will have to be implemented in your concrete classes extending the abstract class.
 
Marshal
Posts: 74069
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create instances of abstract classes, but by indirect routes.
You know that abstract classes are allowed abstract methods? Well, the unimplemented methods in interfaces are abstract methods. If you create an object you must implement them, so whenever you create a concrete subclass of an abstract class (or an anonymous class), you must implement all its methods. You can create instances of the concrete subclasses directly, so they must have all methods implemented.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic