|
Abstract Classes
With Examples in Java |
|
Prof. David Bernstein
|
| Computer Science Department |
| bernstdh@jmu.edu |
abstract modifier,
couldn't we just not have constructors?abstract modifier,
couldn't we just make the constructors private?abstract modifier is more direct/straightforward
private constructors are used for other purposes
along with factory methods (more on this later)
Object which is concrete)
SecurityQuotation Class
toString() method sends
the getSymbol() message to this
(i.e., the abstract getSymbol() method
is called in the concrete toString() method)this refers to an object that was instantiated,
so it must be an element of a concrete class, it must
have an implementation
StockQuotation Derived Class
This class adds a ticker symbol attribute. Since it is a concrete class,
it must implement the getSymbol() method.
FutureQuotation Derived Class
This class adds an attribute for the open interest, the code for the
commodity, and the month and year of the contract. It also adds
an accessor for the open interest and, since it is concrete, implements
the getSymbol() method.
abstract
and static since an abstract method must be
bound dynamically (and, as you can tell from the
modifier, static methods aren't)