Results 1 to 5 of 5

Thread: Abstract Class

  1. #1
    gapper is offline Member
    Join Date
    Jan 2008
    Posts
    17
    Rep Power
    0

    Default 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.

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default 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.
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Unless you have one or more abstract methods there isn't much point in declaring it abstract.
    For discussion see Abstract Methods and Classes.

  4. #4
    jelly's Avatar
    jelly is offline Member
    Join Date
    Jan 2008
    Location
    Somerset, UK
    Posts
    46
    Rep Power
    0

    Default

    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

  5. #5
    gapper is offline Member
    Join Date
    Jan 2008
    Posts
    17
    Rep Power
    0

    Default

    Very interesting discussion indeed.
    2 different points are made ... and both makes a lot of sense.

    Thanks guys.

Similar Threads

  1. Can this be done using abstract class??
    By romina in forum New To Java
    Replies: 6
    Last Post: 03-02-2009, 12:46 PM
  2. Abstract Class with Static Methods
    By bugger in forum New To Java
    Replies: 7
    Last Post: 09-05-2008, 12:20 AM
  3. Interface Vs Abstract Class
    By javarishi in forum New To Java
    Replies: 5
    Last Post: 06-15-2008, 05:43 AM
  4. Replies: 0
    Last Post: 04-02-2008, 07:04 AM
  5. Abstract Class question
    By maa11235 in forum New To Java
    Replies: 1
    Last Post: 01-05-2008, 10:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •