This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes what is the need to declare a class abstract if it doesn't contain abstract methods? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is the need to declare a class abstract if it doesn Watch "what is the need to declare a class abstract if it doesn New topic
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: 492

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: 492

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: 60732
    
  65

Remember, just because you can do something doesn't mean that you should.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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
 
Don't get me started about those stupid light bulbs.
 
subject: what is the need to declare a class abstract if it doesn't contain abstract methods?
 
Similar Threads
difference between BufferedInputStream(or output) and other i/ostreams,regarding buffers.
Reg. native methods
WA #1.....word association
ABSTRACT
Tech Word Game