| Author |
what is the need to declare a class abstract if it doesn't contain abstract methods?
|
preethi kumar
Ranch Hand
Joined: Jun 04, 2010
Posts: 50
|
|
|
can anyone tell me?
|
 |
Hunter McMillen
Ranch Hand
Joined: Mar 13, 2009
Posts: 490
|
|
Abstract classes can't be instantiated(you can't create objects of their type), but they can be subclassed. Which means that another class could inherit all of its methods and attributes; whether those methods are abstract or not is up to the designer.
Example: Assume Java doesn't actually have a Math class
The PI constant in the shape class can be used by the Circle class. This is a poor example because Java provides a Math class that holds constants like PI.
Sun examples:
http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html
Hunter
|
"If the facts don't fit the theory, get new facts" --Albert Einstein
|
 |
preethi kumar
Ranch Hand
Joined: Jun 04, 2010
Posts: 50
|
|
we could have done the same thing without declaring the shape class abstract right?
whats is the difference it made?
|
 |
Hunter McMillen
Ranch Hand
Joined: Mar 13, 2009
Posts: 490
|
|
You could have yes. But in this case Shape was abstract because you wouldn't just want to create a generic Shape object. You wouldnt know how to find the volume of a "Shape", or its circumference, etc..
Hunter
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56191
|
|
|
Remember, just because you can do something doesn't mean that you should.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Bear Bibeault wrote:Remember, just because you can do something doesn't mean that you should.
I can reply to this.
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
preethi kumar
Ranch Hand
Joined: Jun 04, 2010
Posts: 50
|
|
|
thank you so much
|
 |
preethi kumar
Ranch Hand
Joined: Jun 04, 2010
Posts: 50
|
|
|
ya marc you can reply
|
 |
 |
|
|
subject: what is the need to declare a class abstract if it doesn't contain abstract methods?
|
|
|