Can we create abstract class object ?

Abstract class object: Put the same question for an interface. Everyone says anonymously, "no" because there is no implementation (body) of methods as all are abstract. But what about with abstract class?

Coming to an abstract class, the question arises as one variation of abstract class is that it can contain all concrete methods. I mean, an abstract class with all concrete (non-abstract) methods. People ask (of course it is a good question for interviews also for freshers) why we cannot create an instance of an abstract class when all methods are non-abstract.

Only one answer from me.

Can you force an abstract class to contain only non-abstract methods so that object can be created? No, designers did not provide a way. As you cannot force, you cannot create an instance of an abstract class. The same rule applies for all the three variations of abstract class – a) containing all concrete methods b) containing all abstract methods and c) containing a mixture of abstract and concrete methods.

Now let us come to a general discussion (answer) on abstract class object.

Because an abstract class is an incomplete class (incomplete in the sense it contains abstract methods without body and output) we cannot create an instance or object; the same way you say for an interface.

With all the above knowledge, let us write one abstract class with all concrete methods and see the compiler error message when object is created.

abstract class Student
  public void name()              // concrete (non-abstract) method
    System.out.println("Name is Jyostna");
  public void marks()             // concrete (non-abstract) method
    System.out.println("Marks scored are 80");
  public static void main(String args[])
    Student s1 = new Student();   // Error raised, see the errror in screenshot

abstract class object

=============Have indepth knowledge of Abstract classes=============

1. Abstract Classes
2. Abstract class constructor & Interface abstract
3. Abstract Static Method
4. Abstract class with main()

Read for Topics related to In and Outs of interfaces.

4 thoughts on “Can we create abstract class object ?”

  1. But it can be achievable through Anonymous class. In which scenario, we will be instantiate Abstract class. Please correct me if i am wrong.

Leave a Comment

Your email address will not be published.