SlideShare a Scribd company logo
1 of 6
Language | Industrial Training | Digital Marketing | Web Technology | Testing+ |
Database | Networking | Mobile Application | ERP | Graphic | Big Data | Cloud
Computing
Apply Now
Call us:
70-70-90-50-90
In Java, interface is used to achieve abstraction in java. It is a blueprint of class. An interface is not a
class, but it does help create classes. An interface is fully abstract; it has no fields, only method
definitions. A class can implement an interface, and unless the class is abstract, it is forced to
provide concrete implementations for them. Each method declared inside an interface is implicitly
public and abstract, because methods need to be abstract to force implementing classes to provide
implementations and are public, so classes have access to do so.
The only methods with concrete bodies in an interface are static methods and starting with Java 8,
default methods. The interfaces cannot be instantiated, they do not have constructors.
Interfaces that declare no method definitions are called marker interfaces and have the purpose to
mark classes for specific purposes. The most renowned Java marker interface is java.io.Serializable,
which marks objects that can be serialized (their state can be saved to a binary file).
An interface can be declared in its own file as a top-level component, or nested inside another
component. There are two types of interfaces: normal interfaces and annotations.
The difference between abstract classes and interfaces, and when one or the other should be used,
becomes relevant in the context of inheritance. Java supports only single inheritance. This means a
class can only have one superclass.
Advantages of Interface
• Interface support multiple inheritance.
• Interface help to achieve abstraction.
• Interface help to achieve loose coupling.
Syntax
interface interface_name {
// declare fields
// abstract/private/default methods
}
Example of Interface
interface Animal {
public void animalSound(); // interface method (does not have a body)
public void sleep(); // interface method (does not have a body)
}
class Dog implements Animal {
public void animalSound() {
System.out.println("The Dog is: Barking");
}
public void sleep() {
System.out.println("zzzz");
}
}
class Main {
public static void main(String[] args) {
Dog myDog = new Dog();
myDog.animalSound();
myDog.sleep();
}
}
Output
The Dog is: Barking
Zzzz
Multiple Interfaces
interface Dog {
public void dogSound(); // interface method
}
interface Cat {
public void catSound(); // interface method
}
// DemoClass "implements" Dog and Cat
class DemoClass implements Dog, Cat {
public void dogSound() {
System.out.println("Dog Bark");
}
public void catSound() {
System.out.println("Cat Meww");
}
}
class Main {
public static void main(String[] args) {
DemoClass myObj = new DemoClass();
myObj.dogSound();
myObj.catSound();
}
}
Output
Dog Bark
Cat Meww
Call us:
70-70-90-50-90

More Related Content

What's hot

Access specifiers (Public Private Protected) C++
Access specifiers (Public Private  Protected) C++Access specifiers (Public Private  Protected) C++
Access specifiers (Public Private Protected) C++vivekkumar2938
 
Java interfaces
Java interfacesJava interfaces
Java interfacesjehan1987
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singhdheeraj_cse
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Pritom Chaki
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Javaparag
 
Access specifier
Access specifierAccess specifier
Access specifierzindadili
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces Tuan Ngo
 
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
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend classAbhishek Wadhwa
 
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...Simplilearn
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation javaJayasankarPR2
 
Structure of java program diff c- cpp and java
Structure of java program  diff c- cpp and javaStructure of java program  diff c- cpp and java
Structure of java program diff c- cpp and javaMadishetty Prathibha
 
Master of Computer Application (MCA) – Semester 4 MC0078
Master of Computer Application (MCA) – Semester 4  MC0078Master of Computer Application (MCA) – Semester 4  MC0078
Master of Computer Application (MCA) – Semester 4 MC0078Aravind NC
 

What's hot (20)

Access specifiers (Public Private Protected) C++
Access specifiers (Public Private  Protected) C++Access specifiers (Public Private  Protected) C++
Access specifiers (Public Private Protected) C++
 
The smartpath information systems java
The smartpath information systems javaThe smartpath information systems java
The smartpath information systems java
 
[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Java
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
 
Access specifier
Access specifierAccess specifier
Access specifier
 
javainterface
javainterfacejavainterface
javainterface
 
Interface in java
Interface in javaInterface in java
Interface in java
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and 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
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation java
 
Structure of java program diff c- cpp and java
Structure of java program  diff c- cpp and javaStructure of java program  diff c- cpp and java
Structure of java program diff c- cpp and java
 
C# concepts
C# conceptsC# concepts
C# concepts
 
Master of Computer Application (MCA) – Semester 4 MC0078
Master of Computer Application (MCA) – Semester 4  MC0078Master of Computer Application (MCA) – Semester 4  MC0078
Master of Computer Application (MCA) – Semester 4 MC0078
 

Similar to Interface in Java

OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxssuser84e52e
 
Polymorphism and interface in vb.net
Polymorphism and interface in vb.netPolymorphism and interface in vb.net
Polymorphism and interface in vb.netKarthigaGunasekaran1
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview QuestionsKuntal Bhowmick
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfbca23189c
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questionsGradeup
 
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and InterfacesJamsher bhanbhro
 
03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.pptJyothiAmpally
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)Professor Lili Saghafi
 
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
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using ReflectionGanesh Samarthyam
 

Similar to Interface in Java (20)

Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptx
 
Java Interface
Java InterfaceJava Interface
Java Interface
 
Java 6.pptx
Java 6.pptxJava 6.pptx
Java 6.pptx
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 
Polymorphism and interface in vb.net
Polymorphism and interface in vb.netPolymorphism and interface in vb.net
Polymorphism and interface in vb.net
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
Interface &packages
Interface &packagesInterface &packages
Interface &packages
 
1
11
1
 
Suga java training_with_footer
Suga java training_with_footerSuga java training_with_footer
Suga java training_with_footer
 
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
 
03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 

More from Ducat India

Join MCSA Server 2016 And 2019 Course In Noida
Join MCSA Server 2016 And 2019 Course In NoidaJoin MCSA Server 2016 And 2019 Course In Noida
Join MCSA Server 2016 And 2019 Course In NoidaDucat India
 
Apply now for dot net training classes in Noida
Apply now for dot net training classes in NoidaApply now for dot net training classes in Noida
Apply now for dot net training classes in NoidaDucat India
 
Apply now for linux training classes in noida
Apply now for linux training classes in noidaApply now for linux training classes in noida
Apply now for linux training classes in noidaDucat India
 
Apply Now for DevOps Training Classes in Noida
Apply Now for DevOps Training Classes in NoidaApply Now for DevOps Training Classes in Noida
Apply Now for DevOps Training Classes in NoidaDucat India
 
Apply Now for AutoCAD Training Course in Noida
Apply Now for AutoCAD Training Course in NoidaApply Now for AutoCAD Training Course in Noida
Apply Now for AutoCAD Training Course in NoidaDucat India
 
Amazon Elastic Load Balancing
Amazon Elastic Load BalancingAmazon Elastic Load Balancing
Amazon Elastic Load BalancingDucat India
 
AWS Relation Database Services
AWS Relation Database ServicesAWS Relation Database Services
AWS Relation Database ServicesDucat India
 
Microsoft Dynamics CRM – Web Resources
Microsoft Dynamics CRM – Web ResourcesMicrosoft Dynamics CRM – Web Resources
Microsoft Dynamics CRM – Web ResourcesDucat India
 
Kanban Board in Jira
Kanban Board in JiraKanban Board in Jira
Kanban Board in JiraDucat India
 
Test Report Preparation
Test Report PreparationTest Report Preparation
Test Report PreparationDucat India
 
What is Text Analysis?
What is Text Analysis?What is Text Analysis?
What is Text Analysis?Ducat India
 
Data Science Using Scikit-Learn
Data Science Using Scikit-LearnData Science Using Scikit-Learn
Data Science Using Scikit-LearnDucat India
 
Struts 2 – Database Access
Struts 2 – Database AccessStruts 2 – Database Access
Struts 2 – Database AccessDucat India
 
Struts 2 – Interceptors
Struts 2 – InterceptorsStruts 2 – Interceptors
Struts 2 – InterceptorsDucat India
 
Struts 2 – Architecture
Struts 2 – ArchitectureStruts 2 – Architecture
Struts 2 – ArchitectureDucat India
 
Hibernate 5 – merge() Example
Hibernate 5 – merge() ExampleHibernate 5 – merge() Example
Hibernate 5 – merge() ExampleDucat India
 
Hibernate Object States – Transient,Persistent and Detached
Hibernate Object States – Transient,Persistent and DetachedHibernate Object States – Transient,Persistent and Detached
Hibernate Object States – Transient,Persistent and DetachedDucat India
 

More from Ducat India (20)

Join MCSA Server 2016 And 2019 Course In Noida
Join MCSA Server 2016 And 2019 Course In NoidaJoin MCSA Server 2016 And 2019 Course In Noida
Join MCSA Server 2016 And 2019 Course In Noida
 
Apply now for dot net training classes in Noida
Apply now for dot net training classes in NoidaApply now for dot net training classes in Noida
Apply now for dot net training classes in Noida
 
Apply now for linux training classes in noida
Apply now for linux training classes in noidaApply now for linux training classes in noida
Apply now for linux training classes in noida
 
Apply Now for DevOps Training Classes in Noida
Apply Now for DevOps Training Classes in NoidaApply Now for DevOps Training Classes in Noida
Apply Now for DevOps Training Classes in Noida
 
Apply Now for AutoCAD Training Course in Noida
Apply Now for AutoCAD Training Course in NoidaApply Now for AutoCAD Training Course in Noida
Apply Now for AutoCAD Training Course in Noida
 
Amazon Elastic Load Balancing
Amazon Elastic Load BalancingAmazon Elastic Load Balancing
Amazon Elastic Load Balancing
 
AWS Relation Database Services
AWS Relation Database ServicesAWS Relation Database Services
AWS Relation Database Services
 
Microsoft Dynamics CRM – Web Resources
Microsoft Dynamics CRM – Web ResourcesMicrosoft Dynamics CRM – Web Resources
Microsoft Dynamics CRM – Web Resources
 
Field Types
Field TypesField Types
Field Types
 
Sprint in jira
Sprint in jiraSprint in jira
Sprint in jira
 
JIRA Versions
JIRA VersionsJIRA Versions
JIRA Versions
 
Kanban Board in Jira
Kanban Board in JiraKanban Board in Jira
Kanban Board in Jira
 
Test Report Preparation
Test Report PreparationTest Report Preparation
Test Report Preparation
 
What is Text Analysis?
What is Text Analysis?What is Text Analysis?
What is Text Analysis?
 
Data Science Using Scikit-Learn
Data Science Using Scikit-LearnData Science Using Scikit-Learn
Data Science Using Scikit-Learn
 
Struts 2 – Database Access
Struts 2 – Database AccessStruts 2 – Database Access
Struts 2 – Database Access
 
Struts 2 – Interceptors
Struts 2 – InterceptorsStruts 2 – Interceptors
Struts 2 – Interceptors
 
Struts 2 – Architecture
Struts 2 – ArchitectureStruts 2 – Architecture
Struts 2 – Architecture
 
Hibernate 5 – merge() Example
Hibernate 5 – merge() ExampleHibernate 5 – merge() Example
Hibernate 5 – merge() Example
 
Hibernate Object States – Transient,Persistent and Detached
Hibernate Object States – Transient,Persistent and DetachedHibernate Object States – Transient,Persistent and Detached
Hibernate Object States – Transient,Persistent and Detached
 

Recently uploaded

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
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
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
 
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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
“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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
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
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
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
 
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...
 
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
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
“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...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
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
 

Interface in Java

  • 1. Language | Industrial Training | Digital Marketing | Web Technology | Testing+ | Database | Networking | Mobile Application | ERP | Graphic | Big Data | Cloud Computing Apply Now Call us: 70-70-90-50-90
  • 2. In Java, interface is used to achieve abstraction in java. It is a blueprint of class. An interface is not a class, but it does help create classes. An interface is fully abstract; it has no fields, only method definitions. A class can implement an interface, and unless the class is abstract, it is forced to provide concrete implementations for them. Each method declared inside an interface is implicitly public and abstract, because methods need to be abstract to force implementing classes to provide implementations and are public, so classes have access to do so. The only methods with concrete bodies in an interface are static methods and starting with Java 8, default methods. The interfaces cannot be instantiated, they do not have constructors. Interfaces that declare no method definitions are called marker interfaces and have the purpose to mark classes for specific purposes. The most renowned Java marker interface is java.io.Serializable, which marks objects that can be serialized (their state can be saved to a binary file). An interface can be declared in its own file as a top-level component, or nested inside another component. There are two types of interfaces: normal interfaces and annotations.
  • 3. The difference between abstract classes and interfaces, and when one or the other should be used, becomes relevant in the context of inheritance. Java supports only single inheritance. This means a class can only have one superclass. Advantages of Interface • Interface support multiple inheritance. • Interface help to achieve abstraction. • Interface help to achieve loose coupling. Syntax interface interface_name { // declare fields // abstract/private/default methods }
  • 4. Example of Interface interface Animal { public void animalSound(); // interface method (does not have a body) public void sleep(); // interface method (does not have a body) } class Dog implements Animal { public void animalSound() { System.out.println("The Dog is: Barking"); } public void sleep() { System.out.println("zzzz"); } } class Main { public static void main(String[] args) { Dog myDog = new Dog(); myDog.animalSound(); myDog.sleep(); } } Output The Dog is: Barking Zzzz
  • 5. Multiple Interfaces interface Dog { public void dogSound(); // interface method } interface Cat { public void catSound(); // interface method } // DemoClass "implements" Dog and Cat class DemoClass implements Dog, Cat { public void dogSound() { System.out.println("Dog Bark"); } public void catSound() { System.out.println("Cat Meww"); } } class Main { public static void main(String[] args) { DemoClass myObj = new DemoClass(); myObj.dogSound(); myObj.catSound(); } } Output Dog Bark Cat Meww