[3383] in java-interest
re:abstract methods
daemon@ATHENA.MIT.EDU (andrew (a.) francis)
Thu Nov 9 23:24:03 1995
Date: Thu, 9 Nov 1995 10:39:00 -0500
From: "andrew (a.) francis" <andrewfr@bnr.ca>
To: garya@village.org
Cc: "fergal (f.k.) connellan" <connef@bnr.ca>, java-interest@java.sun.com
In message "abstract methods", garya@village.org writes:
AF>If the all the methods of abstract classes had method bodies, I don't
AF>understand why one would want abstract classes in the first place?
AF>(note: I believe the new Java language spec needs the keyword "abstract"
AF>to make a method abstract)
G> I'm not suggesting that all abstract methods have bodies; only that they
G> shoul>If the all the methods of abstract classes had method bodies,
In C++, a class is abstract, if one or more of its methods are abstract.
The same for Java. In the case of C++, a method is abstract if it is declared
in the following manner:
class Foo
{
public:
virtual void Do() = 0;
On the other hand, I believe the new Java language specification requires
the keyword, "abstract" be used, so the following would look like
class Foo
{
abstract public void Do(); // I believe in Java, unless methods
// are final, they act like C++ virtual
// functions
[lines deleted]
G> Yes, but you lose the reason the abstract method exists -- forcing the
G> derived class to override the method. The whole purpose of the abstract
G> method is to force the implementor of a derived class to implement the
G> method. If you don't make it abstract, one can derive and forget to
G> do the override, causing incorrect behavior.
Not really, a major purpose of abstract classes is to impose a particular
interface upon sub-classes, rather then imposing a particular behavior
(the method body provides the behavior).
Cheers,
Andrew
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com