Difference between Abstract Class and Concrete Class in Java

Here you will learn the difference between abstract class and concrete class in Java.

Abstract classes are partially implemented classes. This means that they have some methods which need to be implemented in the derived class. As the object of abstract classes can’t me instantiated, so they just serve the purpose of inheritance. These classes need to have at least one abstract method. An abstract class can extend from only one abstract or concrete class but can implement any number of interfaces.

On the other hand concrete classes are the fully implemented classes, they have all the methods which there definition, and there object can be instantiated. Any programmer, whether novice or an expert in java, will have be using concrete classes. They serve the purpose of actually performing any task or doing some specified work in a module.

Here are the detailed differences between both.

Difference between Abstract Class and Concrete Class in Java

S.No. Feature                     Abstract Concrete
1 Introduction Partially implemented classes. Fully implemented classes.
2 Purpose Used in inheritance. Used to instantiate objects and perform specified task in a module.
3 Object Creation Can’t be instantiated. Generally, are created to instantiate objects.
4 Declaration Keyword ‘abstract’ is used before the class declaration and before the abstract method declaration. Declaration directly starts with the ‘class’ keyword.

Other Major Differences:

  1. The class extending from an abstract class need to implement all its abstract method otherwise should be declared abstract itself.
  2. Abstract class can have both implemented and abstract methods whereas concrete class can only have implemented methods.
  3. Abstract classes can have no method inside it, but if there are methods the one method must be declared as abstract. Concrete classes don’t have any such restriction.
  4. The non abstract methods of an abstract class can be used by the derived class in the same way as they are used in case of inheritance using concrete class.
  5. Abstract class in inherited using the keyword ‘extends’, the same way as concrete class.

Example:

Below if an example of abstract and concrete class.

Animal.java

//Abstract class.
abstract public class Animal{
	
	public void eat(){
		System.out.println("Eating");
	}

	//Abstract methods.
	abstract public int legs();
}

Dog.java

//Concrete class.
public class Dog extends Animal{
	public int legs(){
		return 4;
	}
}

Man.java

//Concrete class.
public class Man extends Animal{
	public int legs(){
		return 2;
	}
}

Main.java

//Concrete class.
public class Main{
	public static void main(String[] args) {
		Man man = new Man();
		Dog dog = new Dog();

		System.out.print("Man ");
		man.eat();
		System.out.println("Man has: "+man.legs()+" legs");

		System.out.println()

		System.out.print("Dog ");
		dog.eat();
		System.out.println("Dog has: "+dog.legs()+" legs");
	}
}

Comment below if you have queries regarding abstract class vs concrete class in java.

1 thought on “Difference between Abstract Class and Concrete Class in Java”

Leave a Comment

Your email address will not be published. Required fields are marked *