×
☰ See All Chapters

Java class vs. abstract class

In this chapter you learn the differences between java class and abstract class.

Class

Abstract Class

A class can contain the following members:

  1. Instance and static variables 

  2. Instance and static block 

  3. Concrete methods (Instance and static) 

  4. Constructor 

Abstract class can contain the following members:

  1. Instance and static variables 

  2. Instance and static block 

  3. Concrete methods (Instance and static) 

  4. Abstract methods 

  5. Constructor 

It is used for doing new concrete implementation.

It is used for doing partial implementation.

We can create objects for class using new keyword.

class A {

}

 

class B {

        A a = new A();

}

We cannot create objects for abstract class. Creating objects for abstract class results into compilation error.

 

Class can be made final.

final class A {

}

Abstract class cannot be declared as final. It results into compilation error.

final abstract class B { // not possible

}

It does not support dynamic polymorphism.

It supports dynamic polymorphism.

 


All Chapters
Author