0% found this document useful (0 votes)
9 views

Interfaces

Uploaded by

mriduljain202003
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Interfaces

Uploaded by

mriduljain202003
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

INTERFACES

OBJECT ORIENTED PROGRAMMING


NAME – MRIDUL SINGH SHYAM SUKHA
UNIVERSITY ROLL NO – 18700120071
REGISTRATION NO – 2018701092
CSE (2020-2024)
PCC- CS503
INTERFACES IN OOPS
An interface is a programming structure/syntax that allows the computer to enforce certain
properties on an object (class). An Interface in java programming language is defined as an
abstract type used to specify the behavior of a class. An interface in Java is a blueprint of a class.
A Java interface contains static constants and abstract methods.
 Interfaces specify what a class must do. It does not tell how to do. It is the blueprint of the class. It specifies a set
of methods that the class has to implement.
SYNTAX:
interface{
//declare constant fields
//declare methods that abstract
}
Example:
interface Player {
int move();
void change(int x);
}
 To declare an interface, use the interface keyword. It is used to provide total abstraction. That means all the methods in
an interface are declared with an empty body and are public and all fields are public, static, and final by default.
 A class that implements an interface must implement all the methods declared in the interface. To implement interface
use implements keyword.

Difference Between Class and Interface:

CLASS INTERFACE
> In class, you can instantiate variables > In an interface, you can’t instantiate
and create an object. variables and create an object.
> Class can contain concrete (with > The interface cannot contain
implementation) methods. concrete(with implementation) methods.
Java program to demonstrate working of interface
Advantages of Interface
 Without bothering about the implementation part, we can achieve the security of
the implementation.
 In Java, multiple inheritance is not allowed, however, you can use an interface to
make use of it as you can implement more than one interface.
Ex – extends keyword is used for an interface to extend more than one interface
syntax:
public interface xx extends y, z
THANK YOU!!

You might also like