Difference between Abstract Class and Concrete Class in Java

05 Apr, 2022
Abstract Class: An abstract class is a type of class in Java that is declared by the abstract keyword. An abstract class cannot be instantiated directly, i.e. the object of such class cannot be created directly using the new keyword. An abstract class can be instantiated either by a concrete subclass or by defining all the abstract method along with the new statement. It may or may not contain an abstract method. An abstract method is declared by abstract keyword, such methods cannot have a body. If a class contains an abstract method, then it also needs to be abstract.Concrete Class: A concrete class in Java is a type of subclass, which implements all the abstract method of its super abstract class which it extends to. It also has implementations of all methods of interfaces it implements.Abstract Class vs Concrete Class 
Modifier: An abstract class is declared using abstract modifier. Concrete class should not be declared using abstract keyword, on doing so, it will also become an abstract class.  Instantiation: An abstract class cannot be instantiated directly, i.e. object of such class cannot be created directly using new keyword. An abstract class can be instantiated either by a concrete subclass or by defining all the abstract method along with the new statement. A concrete class can be instantiated directly, using a new keyword. Example: Invalid direct instantiation of an abstract class. 
Modifier: An abstract class is declared using abstract modifier. Concrete class should not be declared using abstract keyword, on doing so, it will also become an abstract class.  
Instantiation: An abstract class cannot be instantiated directly, i.e. object of such class cannot be created directly using new keyword. An abstract class can be instantiated either by a concrete subclass or by defining all the abstract method along with the new statement. A concrete class can be instantiated directly, using a new keyword. Example: Invalid direct instantiation of an abstract class. 
Java
abstract class DemoAbstractClass {    abstract void display();}  public class JavaApplication {    public static void main(String[] args)    {        DemoAbstractClass AC = new DemoAbstractClass();        System.out.println("Hello");    }}
Compile Error:  
Compile Error:  
prog.java:9: error: DemoAbstractClass is abstract; cannot be instantiated
        DemoAbstractClass AC = new DemoAbstractClass();
                               ^
Example: Valid instantiation by defining all abstract method of an abstract class.  
Example: Valid instantiation by defining all abstract method of an abstract class.  
Java
abstract class DemoAbstractClass {    abstract void display();}  public class JavaApplication {    public static void main(String[] args)    {        DemoAbstractClass AC = new DemoAbstractClass() {            void display()            {                System.out.println("Hi.");            }        };        AC.display();        System.out.println("How are you?");    }}
 
 
Hi.
How are you?
 
Example: Direct instantiation of concrete using new keyword. 
Example: Direct instantiation of concrete using new keyword. 
Java
abstract class DemoAbstractClass {    abstract void display();}  class ConcreteClass extends DemoAbstractClass {    void display()    {        System.out.println("Hi.");    }}  public class JavaApplication {    public static void main(String[] args)    {        ConcreteClass C = new ConcreteClass();        C.display();        System.out.println("How are you?");    }}
 
 
Hi.
How are you?
 
 Abstract methods: An abstract class may or may not, have an abstract method. A concrete class cannot have an abstract method, because class containing an abstract method must also be abstract. Let’s understand this by an example:- We have a class called “HttpServlet” in Servlet. Now, this class is special in its own way. “HttpServlet is an abstract class, but it doesn’t contain any abstract methods”. Let’s understand the meaning of the above statement in-depth:- -> HttpServlet is an abstract class because it doesn’t have proper implementation for its methods. Since it doesn’t have proper implementation for its methods, then what is the sense of creating objects for such class. Therefore, this class is made as abstract.Now Question arises is that:- Q.If methods have not proper implementation, then why they have not made it abstract? -> Since abstract methods are those, which doesn’t have a proper body defining and we override such methods in our class to give it a proper definition. So basically abstract methods are used for overriding purpose. Now this “HttpServlet” class contain 10 methods and suppose if these methods were made abstract then we need to override all the 10 methods of “HttpServlet” class which is a foolish way since we need only doGet()and doPost() methods. public void service(ServletRequest req, ServletResponse res)protected void service(HttpServletRequest req, HttpServletResponse res)protected void doGet(HttpServletRequest req, HttpServletResponse res)protected void doPost(HttpServletRequest req, HttpServletResponse res)protected void doHead(HttpServletRequest req, HttpServletResponse res)protected void doOptions(HttpServletRequest req, HttpServletResponse res)protected void doPut(HttpServletRequest req, HttpServletResponse res)protected void doTrace(HttpServletRequest req, HttpServletResponse res)protected void doDelete(HttpServletRequest req, HttpServletResponse res)protected void getLastModified(HttpServletRequest req)Final: An abstract class cannot be final, because all its abstract methods must defined in the subclass. A concrete class can be declared as final.Interface: An abstract class cannot implement an interface alone but it can implement an interface, by the use of a child class and not providing implementations of all of the interface’s methods. It is the responsibility of the first concrete class that has that abstract class as an ancestor to implement all of the methods in the interface.  
 
Abstract methods: An abstract class may or may not, have an abstract method. A concrete class cannot have an abstract method, because class containing an abstract method must also be abstract. Let’s understand this by an example:- We have a class called “HttpServlet” in Servlet. Now, this class is special in its own way. “HttpServlet is an abstract class, but it doesn’t contain any abstract methods”. Let’s understand the meaning of the above statement in-depth:- -> HttpServlet is an abstract class because it doesn’t have proper implementation for its methods. Since it doesn’t have proper implementation for its methods, then what is the sense of creating objects for such class. Therefore, this class is made as abstract.Now Question arises is that:- Q.If methods have not proper implementation, then why they have not made it abstract? -> Since abstract methods are those, which doesn’t have a proper body defining and we override such methods in our class to give it a proper definition. So basically abstract methods are used for overriding purpose. Now this “HttpServlet” class contain 10 methods and suppose if these methods were made abstract then we need to override all the 10 methods of “HttpServlet” class which is a foolish way since we need only doGet()and doPost() methods. public void service(ServletRequest req, ServletResponse res)protected void service(HttpServletRequest req, HttpServletResponse res)protected void doGet(HttpServletRequest req, HttpServletResponse res)protected void doPost(HttpServletRequest req, HttpServletResponse res)protected void doHead(HttpServletRequest req, HttpServletResponse res)protected void doOptions(HttpServletRequest req, HttpServletResponse res)protected void doPut(HttpServletRequest req, HttpServletResponse res)protected void doTrace(HttpServletRequest req, HttpServletResponse res)protected void doDelete(HttpServletRequest req, HttpServletResponse res)protected void getLastModified(HttpServletRequest req)
public void service(ServletRequest req, ServletResponse res)protected void service(HttpServletRequest req, HttpServletResponse res)protected void doGet(HttpServletRequest req, HttpServletResponse res)protected void doPost(HttpServletRequest req, HttpServletResponse res)protected void doHead(HttpServletRequest req, HttpServletResponse res)protected void doOptions(HttpServletRequest req, HttpServletResponse res)protected void doPut(HttpServletRequest req, HttpServletResponse res)protected void doTrace(HttpServletRequest req, HttpServletResponse res)protected void doDelete(HttpServletRequest req, HttpServletResponse res)protected void getLastModified(HttpServletRequest req)
public void service(ServletRequest req, ServletResponse res)
protected void service(HttpServletRequest req, HttpServletResponse res)
protected void doGet(HttpServletRequest req, HttpServletResponse res)
protected void doPost(HttpServletRequest req, HttpServletResponse res)
protected void doHead(HttpServletRequest req, HttpServletResponse res)
protected void doOptions(HttpServletRequest req, HttpServletResponse res)
protected void doPut(HttpServletRequest req, HttpServletResponse res)
protected void doTrace(HttpServletRequest req, HttpServletResponse res)
protected void doDelete(HttpServletRequest req, HttpServletResponse res)
protected void getLastModified(HttpServletRequest req)
Final: An abstract class cannot be final, because all its abstract methods must defined in the subclass. A concrete class can be declared as final.
Interface: An abstract class cannot implement an interface alone but it can implement an interface, by the use of a child class and not providing implementations of all of the interface’s methods. It is the responsibility of the first concrete class that has that abstract class as an ancestor to implement all of the methods in the interface.  
 
Some important points:  
A concrete class is a subclass of an abstract class, which implements all its abstract method.  
Abstract methods cannot have body.  
Abstract class can have static fields and static method, like other classes.  
An abstract class cannot be declared as final.  
Only abstract class can have abstract methods.  
A private, final, static method cannot be abstract, as it cannot be overridden in a subclass.  
Abstract class cannot have abstract constructors.  
Abstract class cannot have abstract static methods.  
If a class extends an abstract class, then it should define all the abstract methods (override) of the base abstract class. If not, the subclass(the class extending abstract class) must also be defined as abstract class.  
 
AnshulVaidya
binni1108bg
kk773572498
pranav_arya37
Java-Abstract Class and Interface
Java-Classes
Java-Object Oriented
Difference Between
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference Between Method Overloading and Method Overriding in Java
Difference between Compile-time and Run-time Polymorphism in Java
Stack vs Heap Memory Allocation
Difference between Synchronous and Asynchronous Transmission
Difference between Structure and Union in C
Arrays in Java
Arrays.sort() in Java with examples
Reverse a string in Java
Split() String method in Java with examples
Queue Interface In Java