
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Differences Between Abstract Class and Concrete Class in Java
Abstract class and concrete class are fundamental concepts of object oriented programming in Java. In this article, we will learn the differences between an abstract class and concrete class.
What is an Abstract Class?
An abstract class is a class that cannot be used to create objects. It can only be accessed using its subclasses. It can contain abstract methods, which are methods without a body. It acts as a blueprint for its subclasses. It can also contain concrete or regular methods.
Example
This example shows how to implement an abstract class in java:
public class JavaTester { public static void main(String args[]) { Cat lion = new Lion(); lion.eat(); } } // Cat class is an abstract class abstract class Cat { abstract public void eat(); } //Lion class is a concrete class which inherits the Cat class. class Lion extends Cat { public void eat() { System.out.println("Lion eats"); } }
Output
The above program produces the following result :
Lion eats
What is a Concrete Class?
A concrete class in Java is a complete class that has fully implemented methods. A concrete class can be instantiated, which means we can create objects of a concrete class directly using the new keyword. It does not contain any abstract methods.
Example
The following example shows how to implement a concrete class in Java:
public class Cat { void meow() { System.out.println("Cat meows"); } public static void main(String[] args) { Cat myCat = new Cat(); myCat.meow(); } }
Output
The above program produces the following output:
Cat meows
Abstract Class vs Concrete Class
The following table summarizes the differences between abstract and concrete classes:
Sr. No. | Key | Abstract Class | Concrete Class |
---|---|---|---|
1 | Supported Methods | Abstract class can have both an abstract as well as concrete methods. | A concrete class can only have concrete methods. Even a single abstract method makes the class abstract. |
2 | Instantiation | Abstract class cannot be instantiated using new keyword. | Concrete class can be instantiated using new keyword. |
3 | Abstract Method | Abstract class may or may not have abstract methods. | Concrete class can not have an abstract method. |
4 | Final | Abstract class can not be declared as a final class. | Concrete class can be declared final. |
5 | Keyword | Abstract class is declared using abstract keyword. | Concrete class does not use the abstract keyword during declaration. |
6 | Usage | Abstract class requires a subclass to be used. | Concrete class can be used directly without the need of a subclass. |