DEV Community

Cover image for What is class , abstract class & interface .
Rahul Raj
Rahul Raj

Posted on

What is class , abstract class & interface .

What is class ?

  • class is blueprint from which we create object.

  • we declare class with the help of class keyword.

  • Inside the class, we can directly write fields (non-static / static), blocks (non-static / static), constructors, concrete methods (non-static / static), inner classes, interfaces, and so on.

  • Generally, we can create object of class with the help of new keyword.

  • class is also a user-defined data type.

  • we cannot write abstract method inside the normal class.

class

Abstract Class :

  • Abstract class is declare with the abstract keyword .
  • We can not create object of the abstract class .
  • Abstract class may contain non - abstract method ( concrete methods ) , may contain abstract method , may contain non - static field . may contain static field .
  • Abstract class can not be final .
  • for declare abstract class , we use abstract keyword.

Note :

  • Abstract method is type of method having no body . We have to provide body of abstract method in their child class .

abstract class

interface :

  • Interface is a blueprint that contains abstract methods and constant (public static final) variables.
  • for declare interface , we use interface keyword .
  • with the help of interface , we achieve multiple inheritance .

interface

Top comments (0)