2
Most read
5
Most read
9
Most read
P R E S E N T E D B Y :
P R A J J A V A L R A O C H I N T A L
Interface in Java
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.
 It is used to achieve abstraction and multiple
inheritance in Java.
Why use Java interface?
 It is used to achieve abstraction.
 By interface, we can support the functionality of
multiple inheritance.
 It can be used to achieve loose coupling.
Multiple inheritance is not supported
through class in java, but it is possible by
an interface, why?
 multiple inheritance is not supported in the case of
class because of ambiguity.
 However, it is supported in case of an interface
because there is no ambiguity. It is because its
implementation is provided by the implementation
class.
How to declare an interface?
 An interface is declared by using the interface
keyword.
 all the methods in an interface are declared with the
empty body, and all the fields are public, static and
final by default.
 A class that implements an interface must
implement all the methods declared in the interface.
Syntax:
interface <interface_name>
{
// declare constant fields
// declare methods that abstract
// by default.
}
Working of compiler
 The Java compiler adds public and abstract
keywords before the interface method. Moreover, it
adds public, static and final keywords before data
members.
The relationship between classes and
interfaces
 As shown in the figure given below, a class extends
another class, an interface extends another interface,
but a class implements an interface.
Java Interface Example
//Interface declaration: by first user
interface Drawable
{
void draw();
}
//Implementation: by second user
class Rectangle implements Drawable
{
public void draw()
{
System.out.println("drawing
rectangle");
}
}
class Circle implements Drawable
{
public void draw()
{
System.out.println("drawing circle");
}
}
//Using interface: by third user
public class TestInterface1
{
public static void main(String args[])
{
Drawable d=new Circle();//In real
scenario, object is provided by
method e.g. getDrawable()
Drawable r=new Rectangle();
d.draw();
r.draw();
}
}
Multiple inheritance in Java by interface
 If a class implements multiple interfaces, or an
interface extends multiple interfaces, it is known as
multiple inheritance.
Multiple inheritance using interface
interface Printable
{
void print();
}
interface Showable
{
void show();
}
public class A7 implements
Printable,Showable
{
public void print()
{
System.out.println("Hello");
}
public void show()
{
System.out.println("Welcome");
}
public static void main(String
args[])
{
A7 obj = new A7();
obj.print();
obj.show();
}
}

More Related Content

PPTX
MULTI THREADING IN JAVA
PPTX
Interface in java
PPTX
Multi-threaded Programming in JAVA
PPTX
Quine Mc Cluskey Method
PDF
java ppt.pdf
PPTX
Classes objects in java
PPTX
INHERITANCE IN JAVA.pptx
PPT
Java: GUI
MULTI THREADING IN JAVA
Interface in java
Multi-threaded Programming in JAVA
Quine Mc Cluskey Method
java ppt.pdf
Classes objects in java
INHERITANCE IN JAVA.pptx
Java: GUI

What's hot (20)

PPTX
java interface and packages
PPTX
Java abstract class & abstract methods
PPT
Abstract class in java
PDF
Java I/o streams
PPTX
PPT
Java Streams
PPTX
Packages,static,this keyword in java
PPTX
Java package
PPT
Java interfaces
PPTX
Inheritance in JAVA PPT
PPTX
Packages in java
PPT
Exception Handling in JAVA
PDF
Generics
PPT
11 constructors in derived classes
PPTX
Super Keyword in Java.pptx
PDF
Introduction to java (revised)
PPTX
Applet and graphics programming
PPTX
Java swing
PPT
Final keyword in java
PPTX
Java class,object,method introduction
java interface and packages
Java abstract class & abstract methods
Abstract class in java
Java I/o streams
Java Streams
Packages,static,this keyword in java
Java package
Java interfaces
Inheritance in JAVA PPT
Packages in java
Exception Handling in JAVA
Generics
11 constructors in derived classes
Super Keyword in Java.pptx
Introduction to java (revised)
Applet and graphics programming
Java swing
Final keyword in java
Java class,object,method introduction
Ad

Similar to Interface in java ,multiple inheritance in java, interface implementation (20)

DOCX
Java interface
PDF
Basic_Java_10.pdf
PPTX
Interface in java
PDF
Exception handling and packages.pdf
PPTX
it is the quick gest about the interfaces in java
PPT
oops with java modules i & ii.ppt
PPTX
JAVA.pptx
PDF
Interfaces in java
PPTX
INTERFACES. with machine learning and data
PPT
PPTX
Java notes of Chapter 3 presentation slides
PDF
21UCAC31 Java Programming.pdf(MTNC)(BCA)
PPTX
Java Interface
PDF
FINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdf
PPTX
OOFeatures_revised-2.pptx
PPTX
Objects and classes in OO Programming concepts
PPT
12.2 Abstract class and Interface.ppt
PPT
Java interface
PPTX
Lecture 18
Java interface
Basic_Java_10.pdf
Interface in java
Exception handling and packages.pdf
it is the quick gest about the interfaces in java
oops with java modules i & ii.ppt
JAVA.pptx
Interfaces in java
INTERFACES. with machine learning and data
Java notes of Chapter 3 presentation slides
21UCAC31 Java Programming.pdf(MTNC)(BCA)
Java Interface
FINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdf
OOFeatures_revised-2.pptx
Objects and classes in OO Programming concepts
12.2 Abstract class and Interface.ppt
Java interface
Lecture 18
Ad

Recently uploaded (20)

PPTX
Neurological complocations of systemic disease
PPTX
BSCE 2 NIGHT (CHAPTER 2) just cases.pptx
PDF
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
PDF
African Communication Research: A review
PDF
FYJC - Chemistry textbook - standard 11.
PPTX
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
PPTX
Climate Change and Its Global Impact.pptx
PPT
hsl powerpoint resource goyloveh feb 07.ppt
PDF
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
PPTX
2025 High Blood Pressure Guideline Slide Set.pptx
PPTX
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
PDF
Everyday Spelling and Grammar by Kathi Wyldeck
DOCX
EDUCATIONAL ASSESSMENT ASSIGNMENT SEMESTER MAY 2025.docx
PPTX
Neurology of Systemic disease all systems
PDF
Physical education and sports and CWSN notes
PPTX
Why I Am A Baptist, History of the Baptist, The Baptist Distinctives, 1st Bap...
PPTX
Theoretical for class.pptxgshdhddhdhdhgd
PPTX
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
PPTX
Designing Adaptive Learning Paths in Virtual Learning Environments
PPTX
Diploma pharmaceutics notes..helps diploma students
Neurological complocations of systemic disease
BSCE 2 NIGHT (CHAPTER 2) just cases.pptx
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
African Communication Research: A review
FYJC - Chemistry textbook - standard 11.
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
Climate Change and Its Global Impact.pptx
hsl powerpoint resource goyloveh feb 07.ppt
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
2025 High Blood Pressure Guideline Slide Set.pptx
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
Everyday Spelling and Grammar by Kathi Wyldeck
EDUCATIONAL ASSESSMENT ASSIGNMENT SEMESTER MAY 2025.docx
Neurology of Systemic disease all systems
Physical education and sports and CWSN notes
Why I Am A Baptist, History of the Baptist, The Baptist Distinctives, 1st Bap...
Theoretical for class.pptxgshdhddhdhdhgd
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
Designing Adaptive Learning Paths in Virtual Learning Environments
Diploma pharmaceutics notes..helps diploma students

Interface in java ,multiple inheritance in java, interface implementation

  • 1. P R E S E N T E D B Y : P R A J J A V A L R A O C H I N T A L Interface in Java
  • 2. 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.  It is used to achieve abstraction and multiple inheritance in Java.
  • 3. Why use Java interface?  It is used to achieve abstraction.  By interface, we can support the functionality of multiple inheritance.  It can be used to achieve loose coupling.
  • 4. Multiple inheritance is not supported through class in java, but it is possible by an interface, why?  multiple inheritance is not supported in the case of class because of ambiguity.  However, it is supported in case of an interface because there is no ambiguity. It is because its implementation is provided by the implementation class.
  • 5. How to declare an interface?  An interface is declared by using the interface keyword.  all the methods in an interface are declared with the empty body, and all the fields are public, static and final by default.  A class that implements an interface must implement all the methods declared in the interface.
  • 6. Syntax: interface <interface_name> { // declare constant fields // declare methods that abstract // by default. }
  • 7. Working of compiler  The Java compiler adds public and abstract keywords before the interface method. Moreover, it adds public, static and final keywords before data members.
  • 8. The relationship between classes and interfaces  As shown in the figure given below, a class extends another class, an interface extends another interface, but a class implements an interface.
  • 9. Java Interface Example //Interface declaration: by first user interface Drawable { void draw(); } //Implementation: by second user class Rectangle implements Drawable { public void draw() { System.out.println("drawing rectangle"); } } class Circle implements Drawable { public void draw() { System.out.println("drawing circle"); } } //Using interface: by third user public class TestInterface1 { public static void main(String args[]) { Drawable d=new Circle();//In real scenario, object is provided by method e.g. getDrawable() Drawable r=new Rectangle(); d.draw(); r.draw(); } }
  • 10. Multiple inheritance in Java by interface  If a class implements multiple interfaces, or an interface extends multiple interfaces, it is known as multiple inheritance.
  • 11. Multiple inheritance using interface interface Printable { void print(); } interface Showable { void show(); } public class A7 implements Printable,Showable { public void print() { System.out.println("Hello"); } public void show() { System.out.println("Welcome"); } public static void main(String args[]) { A7 obj = new A7(); obj.print(); obj.show(); } }