J2EEOnline
GofPatterns OOPortal
prev next prev next
  Course navigation
 
Lesson 7
Objective
Abstract classes
Learn how abstract classes are close relatives of interfaces.
   
Java interfaces are very similar to abstract classes. An abstract class is simply a class that contains unimplemented methods. When a class is derived from an abstract class it must implement all of the unimplemented methods declared in the abstract class.
Unlike interfaces, abstract classes can contain member variables and implemented methods in addition to unimplemented methods. This makes abstract classes more powerful than interfaces in some respects.
Java does not support multiple inheritance, which means that you can't derive a class from more than one parent class, including abstract classes. On the other hand, classes can implement as many interfaces as they want. This is a critical difference between interfaces and abstract classes, and ultimately makes interfaces more useful than abstract classes in most situations. For this reason, the Java API relies heavily on interfaces but uses abstract classes sparingly.
  Course navigation