The main difference between Abstract Class and Concrete Class is that it is not possible to create objects using an abstract class while using a concrete class, it is possible to create objects.
Object-Oriented Programming (OOP) is a popular paradigm in software development. It helps to develop a real-world scenario easily. Moreover, it also allows programmers to model the software using a set of objects. These objects communicate with other objects to pass messages. Furthermore, an object is created using a class. A concrete class is a default class. One major pillar in OOP is Abstraction. Abstract class is a method of achieving abstraction.
Key Areas Covered
1. What is Abstract Class
– Definition, Functionality
2. What is Concrete Class
– Definition, Functionality
3. Difference Between Abstract Class and Concrete Class
– Comparison of Key Differences
Abstraction, Abstract Class, Class, Concrete Class, OOP
What is Abstract Class
One major concept in OOP is abstraction. It is the process of hiding the internal details and displaying only the functionality to the user. An abstract class is a method of achieving Abstraction. Programming languages such as Java uses abstract keywords to denote an abstract class.
An abstract method is a method without an implementation. Moreover, an abstract class can have abstract methods and non abstract methods. A class can extend an abstract class. Then it can provide the implementations for the abstract methods of the abstract class. Furthermore, an abstract class can have constructors and static methods.
It is not possible to create objects from an abstract class. However, the programmer can create objects from a class that extends an abstract class. If an abstract method in the abstract class is declared as final, then the class that extends the abstract class cannot provide an implementation for the abstract method.
Shape is an abstract class. It has an abstract method called draw and a non abstract method called display. Moreover, the Square class extends Shape. Thus, the Square class can provide an implementation from the abstract method (draw) in the Shape class.
An object of Square is created inside the main method. Finally, the draw method is called using that object. It displays “Square” on the console.
What is Concrete Class
Concrete class is a class that does not have any unimplemented methods. Programming languages such as Java use the class keyword to denote a class. A concrete class is a blueprint to create objects. It has attributes and methods. Attributes represent the properties or data while the methods represent the behaviors of the class. These attributes and methods are the members of the class.
Above is a concrete class called Rectangle. Here, it has two private attributes: length and width. It also has a constructor called Rectangle to provide initial values to the attributes. Furthermore, there is a method called displayArea.
Moreover, this class also has the main method. Inside the main method, an object of rectangle(r) is created and the values 5 and 4 are passed to the constructor. Moreover, the constructor assigns value 5 to length and value 4 to width. Finally, the displayArea method is called using the object. It displays the area of the rectangle on the console.
Difference Between Abstract Class and Concrete Class
An abstract class is a class declared with an abstract keyword which is a collection of abstract and non-abstract methods while a concrete class is a class that allows creating an instance or an object using the new keyword. Thus, this is the main difference between abstract class and concrete class.
Programmers cannot create objects using an abstract class while programmers can create objects using a concrete class.
An abstract class has unimplemented methods while all methods in a concrete class are implemented.
In brief, OOP is a major paradigm in software development, and abstract class and concrete class are two concepts related to OOP. The main difference between Abstract Class and Concrete Class is that it is not possible to create objects using an abstract class while it is possible to create objects using a concrete class.