SlideShare a Scribd company logo
1 of 9
Interface
Interfaces are just a definition of behavior. Java Interface
is not a class but it is defined in away similar to the class
definition. An Interface describes the functions and
behaviors of a specific object type but doesn't implement
them. When a class implements an interface it has to
implement all methods declared in that interface.
Definition
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.
public interface NameOfInterface
{
// Any number of final, static fields
// Any number of abstract method declarations
}
Syntax - Declaration
interface Printable
{
void print();
}
interface Showable extends Printable
{
void show();
}
class TestInterface4 implements Showable
{
public void print() { System.out.println("Hello"); }
public void show() { System.out.println("Welcome"); }
public static void main(String args[])
{
TestInterface4 obj = new TestInterface4();
obj.print();
obj.show();
}
}
Example - Interface extends interface
interface printable
{
void print();
}
class A6 implements printable
{
public void print()
{
System.out.println("Hello");
}
public static void main(String args[])
{
A6 obj = new A6();
obj.print();
}
}
Example - Class implements interface
interface A
{
int x=10;
}
interface B
{
int x=100;
}
class Hello implements A,B
{
public static void Main(String args[])
{
// reference to x is ambiguous both variables are
x
System.out.println(x);
System.out.println(A.x);
System.out.println(B.x);
}
Example –Accessing Interface Variable
1. Interface functions should be public and abstract.
2. Interface fields should be public and final.
3. Use the Keyword interface to define an interface.
4. If you define a public interface with
name myInterface the java file should be named
as myInterface.java (Similar to public class definition
rules).
5. A class implementing an interface should use the
keyword implements.
6. No objects can be created from an interface.
7. Interfaces don't have constructors as they can't be
initiated
8. An Interface can extends one or more interfaces.
9. You can define a reference of type interface but you
should assign to it an object instance of class type which
Some KEYNOTEs about Interface
1) Java interfaces are slower and more limited than other
ones.
2) Interface should be used multiple number of times else
there is hardly any use of having them
1. Process standardization
2. Implement Multiple Inheritance
3. It is used to achieve abstraction.
4. Security Implementation
Advantage of Java
Disadvantages
Thank
You

More Related Content

What's hot

What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...Edureka!
 
Interface java
Interface java Interface java
Interface java atiafyrose
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classesShreyans Pathak
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasShahzad Younas
 
Interfaces and abstract classes
Interfaces and abstract classesInterfaces and abstract classes
Interfaces and abstract classesAKANSH SINGHAL
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend classAbhishek Wadhwa
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Raffi Khatchadourian
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Javaparag
 
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...Raffi Khatchadourian
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classesasadsardar
 
Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding InterfacesBhushan Mulmule
 

What's hot (20)

What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
 
Java interface
Java interfaceJava interface
Java interface
 
Interface java
Interface java Interface java
Interface java
 
Java interface
Java interface Java interface
Java interface
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Friend Function
Friend FunctionFriend Function
Friend Function
 
Interfaces
InterfacesInterfaces
Interfaces
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
Interfaces and abstract classes
Interfaces and abstract classesInterfaces and abstract classes
Interfaces and abstract classes
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Java
 
Java interface
Java interfaceJava interface
Java interface
 
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classes
 
14 interface
14  interface14  interface
14 interface
 
Interface
InterfaceInterface
Interface
 
Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding Interfaces
 

Similar to Java Interface

21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)ssuser7f90ae
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.pptrani marri
 
12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.pptVISHNUSHANKARSINGH3
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfbca23189c
 
Lecture 5 interface.pdf
Lecture  5 interface.pdfLecture  5 interface.pdf
Lecture 5 interface.pdfAdilAijaz3
 
Interface in Java
Interface in JavaInterface in Java
Interface in JavaDucat India
 
Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdfKp Sharma
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxssuser84e52e
 
Visula C# Programming Lecture 8
Visula C# Programming Lecture 8Visula C# Programming Lecture 8
Visula C# Programming Lecture 8Abou Bakr Ashraf
 
Interface
InterfaceInterface
Interfacevvpadhu
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
this keyword in Java.pptx
this keyword in Java.pptxthis keyword in Java.pptx
this keyword in Java.pptxParvizMirzayev2
 

Similar to Java Interface (20)

Basic_Java_10.pdf
Basic_Java_10.pdfBasic_Java_10.pdf
Basic_Java_10.pdf
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.ppt
 
12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt
 
Interface
InterfaceInterface
Interface
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Lecture 5 interface.pdf
Lecture  5 interface.pdfLecture  5 interface.pdf
Lecture 5 interface.pdf
 
Interface in Java
Interface in JavaInterface in Java
Interface in Java
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Java 06
Java 06Java 06
Java 06
 
Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdf
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Interface
InterfaceInterface
Interface
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptx
 
Visula C# Programming Lecture 8
Visula C# Programming Lecture 8Visula C# Programming Lecture 8
Visula C# Programming Lecture 8
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Interface
InterfaceInterface
Interface
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
this keyword in Java.pptx
this keyword in Java.pptxthis keyword in Java.pptx
this keyword in Java.pptx
 

More from Manish Tiwari

Interview Question, Oracle PLSQL, PLSQL Developer
Interview Question, Oracle PLSQL, PLSQL DeveloperInterview Question, Oracle PLSQL, PLSQL Developer
Interview Question, Oracle PLSQL, PLSQL DeveloperManish Tiwari
 
Oracle SQL, Job Roles, Certification, DML Statement
Oracle SQL, Job Roles, Certification, DML StatementOracle SQL, Job Roles, Certification, DML Statement
Oracle SQL, Job Roles, Certification, DML StatementManish Tiwari
 
Global Software Development, Work Outsourcing, Global Software Industry
Global Software Development, Work Outsourcing, Global Software IndustryGlobal Software Development, Work Outsourcing, Global Software Industry
Global Software Development, Work Outsourcing, Global Software IndustryManish Tiwari
 
Wavelet, Wavelet Image Compression, STW, SPIHT, MATLAB
Wavelet, Wavelet Image Compression, STW, SPIHT, MATLABWavelet, Wavelet Image Compression, STW, SPIHT, MATLAB
Wavelet, Wavelet Image Compression, STW, SPIHT, MATLABManish Tiwari
 
Java Program Structure
Java Program StructureJava Program Structure
Java Program StructureManish Tiwari
 
1 blogging manish_tiwari
1 blogging manish_tiwari1 blogging manish_tiwari
1 blogging manish_tiwariManish Tiwari
 

More from Manish Tiwari (8)

Interview Question, Oracle PLSQL, PLSQL Developer
Interview Question, Oracle PLSQL, PLSQL DeveloperInterview Question, Oracle PLSQL, PLSQL Developer
Interview Question, Oracle PLSQL, PLSQL Developer
 
Oracle SQL, Job Roles, Certification, DML Statement
Oracle SQL, Job Roles, Certification, DML StatementOracle SQL, Job Roles, Certification, DML Statement
Oracle SQL, Job Roles, Certification, DML Statement
 
Global Software Development, Work Outsourcing, Global Software Industry
Global Software Development, Work Outsourcing, Global Software IndustryGlobal Software Development, Work Outsourcing, Global Software Industry
Global Software Development, Work Outsourcing, Global Software Industry
 
Wavelet, Wavelet Image Compression, STW, SPIHT, MATLAB
Wavelet, Wavelet Image Compression, STW, SPIHT, MATLABWavelet, Wavelet Image Compression, STW, SPIHT, MATLAB
Wavelet, Wavelet Image Compression, STW, SPIHT, MATLAB
 
Java Program Structure
Java Program StructureJava Program Structure
Java Program Structure
 
Java Array String
Java Array StringJava Array String
Java Array String
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
1 blogging manish_tiwari
1 blogging manish_tiwari1 blogging manish_tiwari
1 blogging manish_tiwari
 

Recently uploaded

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 

Recently uploaded (20)

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 

Java Interface

  • 2. Interfaces are just a definition of behavior. Java Interface is not a class but it is defined in away similar to the class definition. An Interface describes the functions and behaviors of a specific object type but doesn't implement them. When a class implements an interface it has to implement all methods declared in that interface. Definition 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.
  • 3. public interface NameOfInterface { // Any number of final, static fields // Any number of abstract method declarations } Syntax - Declaration
  • 4. interface Printable { void print(); } interface Showable extends Printable { void show(); } class TestInterface4 implements Showable { public void print() { System.out.println("Hello"); } public void show() { System.out.println("Welcome"); } public static void main(String args[]) { TestInterface4 obj = new TestInterface4(); obj.print(); obj.show(); } } Example - Interface extends interface
  • 5. interface printable { void print(); } class A6 implements printable { public void print() { System.out.println("Hello"); } public static void main(String args[]) { A6 obj = new A6(); obj.print(); } } Example - Class implements interface
  • 6. interface A { int x=10; } interface B { int x=100; } class Hello implements A,B { public static void Main(String args[]) { // reference to x is ambiguous both variables are x System.out.println(x); System.out.println(A.x); System.out.println(B.x); } Example –Accessing Interface Variable
  • 7. 1. Interface functions should be public and abstract. 2. Interface fields should be public and final. 3. Use the Keyword interface to define an interface. 4. If you define a public interface with name myInterface the java file should be named as myInterface.java (Similar to public class definition rules). 5. A class implementing an interface should use the keyword implements. 6. No objects can be created from an interface. 7. Interfaces don't have constructors as they can't be initiated 8. An Interface can extends one or more interfaces. 9. You can define a reference of type interface but you should assign to it an object instance of class type which Some KEYNOTEs about Interface
  • 8. 1) Java interfaces are slower and more limited than other ones. 2) Interface should be used multiple number of times else there is hardly any use of having them 1. Process standardization 2. Implement Multiple Inheritance 3. It is used to achieve abstraction. 4. Security Implementation Advantage of Java Disadvantages