What is an abstract class?

14/04/2008

A class containing atleast one abstract method is called an abstract class. A method that has no implementation and which is expected to be implemented by a subclass is called an abstract method. An Abstract class cannot be instantiated. It is expected to be extended by a subclass. An abstract class may contain static variables declared. Any class with an abstract method must be declared explicitly as abstract. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

Ads by Google

18 comments on “What is an abstract class?

  1. This site is very good and simple. I do have a question here. The first line says – “A class containing atleast one abstract method is called an abstract class” –

    Isn’t it incorrect?

    However in the last line you have mentioned clearly that abstract class may not have an abstract method.

    regards,
    prasanth

  2. The abstract class may or may not have the abstract method. But if you have any abstract method then the class should be Abstract.

  3. 1. A class containing atleast one abstract method is called an abstract class.

    2. A class may be declared abstract even if it has no abstract methods.

    ?????…

  4. can abstract class have constructor ?

  5. An abstract class is simple a class which cant be instantiated.
    An abstract method defined within an abstract class must be implemented by all of its subclass.
    Abstract method cannot be instantiated,it is generally used for inherited.

  6. An abstract class may or may not have abstract methods.

    public abstract class AAA
    {
    }

    Bibhudutta Pradhan.

  7. An abstract class may or may not have abstract methods.

    public abstract class AAA
    {
    }

  8. Hi Joe,
    Initially you said[first sentance of this topic], an abstract class should have atleast one abstract method. This is wrong know? It can have only instance methods as you mentioned at last.

    Thanks,
    Sharat

  9. Can anyone please explain with an example?

  10. HI All
    Does Abastract class contains Constructor ?

    • abstract class contains default constructor,this constructor will be executed when ever we are creating an object of its sub class for initialization instance variables

  11. y we cant instantiated the abstract class,please explain me detaillyy

  12. y we cant instantiated the abstract class,please explain me detailly

    • because abstract class does not have full implementation of method. If we instantiate the abstract class, it would be incomplete instantiation. We can not use such type of instance because of incomplete method body. That’s why the technology restrict to us making a instance of Abstract class.

  13. no, if we declare abstract method as static it shows compile time error. because if we declare abstract method as static it can’t be implemented.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

ABOUT
I am Joe, author of this blog. I run javapapers with loads of passion. If you are into java, you may find lot of interesting things around.
Ads by Google
STAY in TOUCH:

Email:

Core Java | Servlet | JSP | Design Patterns | Android | Spring | Web Service | © 2008-2012 javapapers.