Class, Abstract Class, and Interface

Jinwon Park
1 min readJan 10, 2022

Class is simply a blueprint to the object.

Objects have two characteristics, state and behavior.

Take person as example. A person has state(name, age, height, weight), and behavior(sleep, exercise, eat).

A person’s blueprint(class) can be something like this.

public class Person {
String name;
int age;
float weight;
float height;
public void sleep() {}
public void exercise() {}
public void eat() {}
}

Abstract classes and interface are needed to achieve abstraction, which is one of the key concepts of Object Oriented Programming.

Abstraction is process of hiding complex implementation and exposing simpler interface.

To achieve this, there are two methods: abstract class and interface.

Abstract class

  • can have abstract and non-abstract method.
  • doesn’t support multiple inheritance.
  • can have final, non-final, static, and non-static variables.
  • uses “extends” keyword

It is useful when you want to achieve abstraction that is tightly coupled.

Interface

  • only abstract methods. (default and static methods after Java 8)
  • supports multiple inheritance
  • only static and final variables
  • uses “implements” keyword

It is useful to use in loosely coupled abstraction.

Both abstract class and interface act as a blueprint to the class.

--

--