01-11-2012, 03:23 PM
Abstract Classes, Multiple Inheritance, and Interfaces
Abstract Classes,.ppt (Size: 45.5 KB / Downloads: 21)
What can we consider Abstract?
We can abstract two things in Java:
Classes
Methods
We can't abstract primitive data or objects
Objects are concrete
Abstract Methods
Very similar to a function prototype from C
Similar to Virtual Functions in C++
We provide
Visibility
Return Type
Identifier
Argument
We do not provide any method implementation
Abstract Method Restriction
No class with an abstract method may be instantiated
Java would not know what to do if that method was ever called
You need to declare the class with an abstract method as an abstract class
Abstract Classes
We can declare a class to be abstract
An abstract class cannot be instantiated
An abstract must be extended
An abstract class is a generalization of a group of objects
Members of the group may have specific features
Consider the Following:
Consider
Student as an abstract class
Junior as a specific class
Terry may be an Junior type object
The Student class may describe general properties of all classes
The Junior class may refine that description
An specific student may be a Junior, but not a Student.
Interfaces
Interfaces define what methods must be supported by a class
But it does not specify the implementation
It may also specify constants
We can use interfaces in many of the same places we use classes
As ‘types’ in argument lists
Using instanceof operator