Abstract methods - Abstract methods are those that must be overridden in a subclass
- If any methods are abstract, then the class is abstract
- An abstract class cannot be instantiated (that is, no objects of that class can be created)
The word `abstract' here has no connection at all with the normal meaning of the word (e.g., `abstract art'). An abstract class is one for which no objects can exist. Here is an example. Circles , Squares and Lines are Types of Shape . Any shape can be drawn, so it is sensible for the Shape class to have a draw() method. However, a Shape object itself cannot exist; only its subclasses Circle , Square and Line can have real objects. So although Shape has a draw() method, this method is abstract, as is the class itself. We might define the Shape class something like this: abstract class Shape { // Shape variables go here public abstract void draw(); } The following line of Java : Shape myShape = new Shape(); will produce an error message to the effect that Shape is abstract and cannot be instantiated. When we create the subclasses, they must provide draw() methods, because the Shape class is abstract due to the abstract method draw(). Back to top 
RITSEC - Global Campus Copyright © 1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |