• Articles
  • Tutorials
  • Interview Questions

Abstract Class and Interface in Java - A Beginner's Guide

Tutorial Playlist

Abstract classes are one of the key features of object-oriented programming. They help establish default behavior for subclasses, and are mainly used to achieve abstraction in classes. Another way to achieve abstraction is through interfaces. In this section of the Java tutorial, you will learn comprehensively about abstract classes and interfaces in Java.

Abstract Class in Java

Class declared with Abstract keyword is known as abstract class in java.  This abstract class have abstract and non-abstract methods. Basically abstract is a process of hiding the properties and showing only functionality to the user. It shows only important things to the user and hides the internal details.

abstract class ClassOne
{
abstract public void method();
public void method1()
{
System.out.println("Method");
}
}
class ClassTwo extends ClassOne
{
public void method()
{
System.out.println("Method 2");
}
}

Learn Java

Learn the 5 types of Java Tokens and how to use them in your code!

Interfaces in Java

It is not a class, all methods declared in this block are incomplete. Interface block should be declared with ‘interface’ keyword.  Interface is a blueprint of class. Java core part and a way to achieve data  abstraction in java along with abstract class.  Multiple interface implementation allows to implemented subclass. It is fully abstract class. Here no need to declare abstract keyword and no need to declare interface keyword for all methods.  Let see the example.

interface Program1
{
public void method1();
}
class MyProgram1 implements Program1
{
public void method1()
{
System.out.println("hello this is overrided method..");
}
}

Get the whole knowledge about Java through our Java Tutorial.

Difference between Abstract class and Interface in Java

Abstract class Interface
It can have abstract and non abstract methods. It can have only abstract methods.
abstract keyword is used to declare abstract class interface keyword is used to declare interface.
It can contain static methods, main method and constructor. It cannot contain static methods, main method or constructor.
It does not support multiple inheritance. It supports multiple inheritance.
It can have final, non-final, static and non-static variables. It has only static and final variables.
It can provide the implementation of interface. It cannot provide the implementation of abstract class.

Read On: Encapsulation in Java

Course Schedule

Name Date Details
Python Course 20 Apr 2024(Sat-Sun) Weekend Batch
View Details
Python Course 27 Apr 2024(Sat-Sun) Weekend Batch
View Details
Python Course 04 May 2024(Sat-Sun) Weekend Batch
View Details

Full-Stack-ad.jpg