Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
abstract
concrete
interface
oop

Difference between interface, abstract, and concrete classes

Educative Answers Team

Interface

An interface in Java is a class that provides data abstraction. Abstraction is a way to hide non-relevant and non-essential information from users.

Interface example

No methods are implemented.

interface Animal {
   String Name;
   public void eat();
   public void drink();
}

Abstract class

An abstract class in Java is a class that has abstract methods. It uses the keyword abstract.

Abstract class example

Methods may or may not be implemented

abstract class Animal {
   String Name;
   public void eat();
   {
     System.out.println("I eat");
   }
   public void drink();
}

Concrete class

A concrete class in Java has data members, methods, and their implementations.

Concrete class example

All methods are implemented.

public class Animal {
   String Name;
   public void eat();
   {
     System.out.println("I eat");
   }
   public void drink()
   {
     System.out.println("I drink");
   }
}

Difference between these three classes

The simplest difference between all three of these classes is​:

  • an interface has no method implementation
  • abstract classes may or may not have method implementation
  • concrete classes MUST have method implementation

RELATED TAGS

java
abstract
concrete
interface
oop
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring