0% found this document useful (0 votes)
22 views7 pages

Interface 23march

An interface in Java is a blueprint of a class that defines abstract methods and constants but cannot define method bodies. Interfaces are used to represent IS-A relationships and achieve abstraction and multiple inheritance. An interface is declared using the interface keyword and defines abstract methods without method bodies. Classes can implement interfaces to inherit their abstract methods and constants.

Uploaded by

Rutuja Kadam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Interface 23march

An interface in Java is a blueprint of a class that defines abstract methods and constants but cannot define method bodies. Interfaces are used to represent IS-A relationships and achieve abstraction and multiple inheritance. An interface is declared using the interface keyword and defines abstract methods without method bodies. Classes can implement interfaces to inherit their abstract methods and constants.

Uploaded by

Rutuja Kadam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

INTERFACE IN JAVA

BATCH-5
KADAM RUTUJA
WHAT IS AN INTERFACE?

 An interface in Java is a blueprint of a class. It has static constants and abstract


methods.
 The interface in Java is a mechanism to achieve abstraction. There can be only
abstract methods in the Java interface, not method body. It is used to achieve
abstraction and multiple inheritance in java. In other words, you can say that
interfaces can have abstract methods and variables. It cannot have a method body.
 Java Interface also represents the IS-A relationship.
WHY USE JAVA INTERFACE?
HOW TO DECLARE AN INTERFACE?

 An interface is declared by using the interface keyword.


 Syntax
interface <interface_name>{

// declare constant fields


// declare methods that abstract
// by default.
}
THE RELATIONSHIP BETWEEN CLASSES AND
INTERFACES
JAVA INTERFACE EXAMPLE: DRAWABLE
interface Drawable
{
void draw(); class TestInterface1
} {
public static void main(String args[])
class Rectangle implements Drawable {
{ Drawable d=new Circle();
public void draw() d.draw();
{ }
System.out.println("drawing rectangle"); }
}
}
class Circle implements Drawable
Output:
{ drawing circle
public void draw(){System.out.println("drawing circle");}
}
Thank You

You might also like