• Articles
  • Tutorials
  • Interview Questions

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

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

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 23 Nov 2024(Sat-Sun) Weekend Batch View Details
30 Nov 2024(Sat-Sun) Weekend Batch
07 Dec 2024(Sat-Sun) Weekend Batch

About the Author

Senior Consultant Analytics & Data Science

Sahil Mattoo, a Senior Software Engineer at Eli Lilly and Company, is an accomplished professional with 14 years of experience in languages such as Java, Python, and JavaScript. Sahil has a strong foundation in system architecture, database management, and API integration.