Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-30-2008, 10:32 PM
Member
 
Join Date: Jan 2008
Posts: 17
gapper is on a distinguished road
Abstract Class
I have to take a design decision. I have a super class that is being inherited by a couple of classes. Working fine.

If I declare it Abstract, it works as it is. I understand that one cannot instantiate Abstract class, but I don't need to do that.

Is it ok to declare it Abstract?

Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-30-2008, 10:54 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 291
tim is on a distinguished road
Abstract classes
Hello gapper.

Classes are defined to be abstract if you know that instances cannot or should not be created from them. Like the class, Animal, should be abstract because we cannot create an animal with no information about it. But, we can create a Dog, which is a subclass of Animal. A family of classes containing abstract classes are usually designed so to prevent illegal usage and logical errors.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-31-2008, 03:18 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,015
hardwired is on a distinguished road
Unless you have one or more abstract methods there isn't much point in declaring it abstract.
For discussion see Abstract Methods and Classes.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-31-2008, 01:45 PM
jelly's Avatar
Member
 
Join Date: Jan 2008
Location: Somerset, UK
Posts: 46
jelly is on a distinguished road
I am afraid I would disagree. Even if there are no abstract methods there may be a point in declaring it abstract. As Tim says the point of abstract is that the class cannot ( in the case of abstract methods) or should not be instantiated directly. I may choose to have a super class that has only concrete methods that will be inherited by, and used by, sub classes but I do not wish to allow the superclass to be instantiated directly, i.e. it is an architectural decision.
__________________
-- Hope that helps
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-31-2008, 02:25 PM
Member
 
Join Date: Jan 2008
Posts: 17
gapper is on a distinguished road
Very interesting discussion indeed.
2 different points are made ... and both makes a lot of sense.

Thanks guys.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interface Vs Abstract Class javarishi New To Java 5 06-15-2008 06:43 AM
what is the Priority for execution of Interface class and a Abstract class Santoshbk Advanced Java 0 04-02-2008 08:04 AM
Abstract Class question maa11235 New To Java 1 01-05-2008 11:30 PM
Abstract Class with Static Methods bugger New To Java 4 01-04-2008 01:12 PM
Can this be done using abstract class?? romina New To Java 2 07-26-2007 10:09 AM


All times are GMT +3. The time now is 03:13 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org