SlideShare a Scribd company logo
1 of 8
Interfaces 
Kaustubh Joshi
Interfaces 
 An interface declares (describes) methods but 
does not supply bodies for them 
 interface interFaceName{ 
public void function1(Class1 obj1); 
public void function2(Class2 obj2); 
} 
 All the methods are implicitly public and 
abstract 
 You can add these qualifiers if you like, but why 
bother? 
 You cannot instantiate an interface 
 An interface is like a very abstract class—none of 
its methods are defined 
 An interface may also contain constants (final 
variables) which act like constants 
2
Implementin 
g an 
interface 
 You extend a class, but you implement an 
interface 
 A class can only extend (subclass) one other class, 
but it can implement as many interfaces as you like 
 Example: 
class otherClass 
implements Interface1, Interface2 { 
//declarations 
} 
3
What are 
interfaces 
for? 
 Reason 1: A class can only extend one other class, but it 
can implement multiple interfaces 
 This lets the class fill multiple “roles” 
 This concept could be explained as partial multiple 
inheritance 
 In writing Applets, it is common to have one class 
implement several different listeners 
 Example: 
class otherClass extends Applet 
implements Interface1, Interface2 { 
//Statements 
} 
 Reason 2: You can write methods that work for more than 
one kind of class 
4
 instanceof is a keyword that tells you whether 
a variable 
“is a” member of a class or interface 
 For example, if 
class Dog extends Animal implements Pet {...} 
Animal fido = new Dog(); 
then the following are all true: 
fido instanceof Dog 
fido instanceof Animal 
fido instanceof Pet 
 instanceof is seldom used 
 When you find yourself wanting to use instanceof, 
think about whether the method you are writing 
should be moved to the individual subclasses 
5 
Instance of
 When you implement an interface, you promise to define all 
the functions it declares 
 There can be a lot of methods 
interface KeyListener { 
public void keyPressed(KeyEvent e); 
public void keyReleased(KeyEvent e); 
public void keyTyped(KeyEvent e); 
} 
 What if you only care about a couple of these methods? 
6 
Interfaces 
again
 Solution: use an adapter class 
 An adapter class implements an interface and 
provides empty method bodies 
class KeyAdapter implements KeyListener { 
public void keyPressed(KeyEvent e) { }; 
public void keyReleased(KeyEvent e) { }; 
public void keyTyped(KeyEvent e) { }; 
} 
 You can override only the methods you care 
about 
 This isn’t elegant, but it does work 
 Java provides a number of adapter classes 
7 
Adapter 
class
Vocabulary 
 abstract method—a method which is declared but not 
defined (it has no method body) 
 abstract class—a class which either (1) contains abstract 
methods, or (2) has been declared abstract 
 instantiate—to create an instance (object) of a class 
 interface—similar to a class, but contains only abstract 
methods (and possibly constants) 
 adapter class—a class that implements an interface but 
has only empty method bodies 
8

More Related Content

What's hot (20)

Interface in java
Interface in javaInterface in java
Interface in java
 
Abstract method
Abstract methodAbstract method
Abstract method
 
Static keyword u.s ass.(2)
Static keyword u.s ass.(2)Static keyword u.s ass.(2)
Static keyword u.s ass.(2)
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
8abstact class in c#
8abstact class in c#8abstact class in c#
8abstact class in c#
 
Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8
 
Vvi
VviVvi
Vvi
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Oop
OopOop
Oop
 
Chapter 09
Chapter 09Chapter 09
Chapter 09
 
Implementing polymorphism
Implementing polymorphismImplementing polymorphism
Implementing polymorphism
 
LPR - Week 2 - DEputty.pdf
LPR - Week 2 - DEputty.pdfLPR - Week 2 - DEputty.pdf
LPR - Week 2 - DEputty.pdf
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
C#
C#C#
C#
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
C# interview quesions
C# interview quesionsC# interview quesions
C# interview quesions
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Java
JavaJava
Java
 
2- Introduction to java II
2-  Introduction to java II2-  Introduction to java II
2- Introduction to java II
 
14 interface
14  interface14  interface
14 interface
 

Viewers also liked

Goose chasegroup
Goose chasegroupGoose chasegroup
Goose chasegroupLes Davy
 
Deber de imformatica jimena y galo
Deber de imformatica jimena y galoDeber de imformatica jimena y galo
Deber de imformatica jimena y galojime15
 
Denk Modulair, Denk Lego
Denk Modulair, Denk LegoDenk Modulair, Denk Lego
Denk Modulair, Denk LegoIde Koops
 
Nutrición vs Alimentación
Nutrición vs AlimentaciónNutrición vs Alimentación
Nutrición vs Alimentacióncharito ybarra
 
วัดพระศรีรัตนศาสดาราม 4121
วัดพระศรีรัตนศาสดาราม 4121วัดพระศรีรัตนศาสดาราม 4121
วัดพระศรีรัตนศาสดาราม 4121marut4121
 
Week Aef4 11
Week Aef4 11Week Aef4 11
Week Aef4 11Les Davy
 
Brand story of Nalacity Foundation
Brand story of Nalacity FoundationBrand story of Nalacity Foundation
Brand story of Nalacity FoundationNalacity Shop
 
Voto de Gilmar Mendes em 15/09/2005
Voto de Gilmar Mendes em 15/09/2005Voto de Gilmar Mendes em 15/09/2005
Voto de Gilmar Mendes em 15/09/2005Miguel Rosario
 
Cables Brochure Web
Cables Brochure WebCables Brochure Web
Cables Brochure Webgm330
 
Дмитрий Волох_фулфилмент_Owox_2014
Дмитрий Волох_фулфилмент_Owox_2014Дмитрий Волох_фулфилмент_Owox_2014
Дмитрий Волох_фулфилмент_Owox_2014TOCHKA
 
Oh the Places You'll Go
Oh the Places You'll GoOh the Places You'll Go
Oh the Places You'll Gomsawesome
 

Viewers also liked (18)

Module1
Module1Module1
Module1
 
Notam 24-04-2015
Notam 24-04-2015Notam 24-04-2015
Notam 24-04-2015
 
Goose chasegroup
Goose chasegroupGoose chasegroup
Goose chasegroup
 
Deber de imformatica jimena y galo
Deber de imformatica jimena y galoDeber de imformatica jimena y galo
Deber de imformatica jimena y galo
 
Denk Modulair, Denk Lego
Denk Modulair, Denk LegoDenk Modulair, Denk Lego
Denk Modulair, Denk Lego
 
Magazine design evaluation pp
Magazine design evaluation ppMagazine design evaluation pp
Magazine design evaluation pp
 
公共施設白書を知ろう会 資料
公共施設白書を知ろう会 資料公共施設白書を知ろう会 資料
公共施設白書を知ろう会 資料
 
Nutrición vs Alimentación
Nutrición vs AlimentaciónNutrición vs Alimentación
Nutrición vs Alimentación
 
2 wireless
2 wireless2 wireless
2 wireless
 
วัดพระศรีรัตนศาสดาราม 4121
วัดพระศรีรัตนศาสดาราม 4121วัดพระศรีรัตนศาสดาราม 4121
วัดพระศรีรัตนศาสดาราม 4121
 
Week Aef4 11
Week Aef4 11Week Aef4 11
Week Aef4 11
 
Brand story of Nalacity Foundation
Brand story of Nalacity FoundationBrand story of Nalacity Foundation
Brand story of Nalacity Foundation
 
Voto de Gilmar Mendes em 15/09/2005
Voto de Gilmar Mendes em 15/09/2005Voto de Gilmar Mendes em 15/09/2005
Voto de Gilmar Mendes em 15/09/2005
 
Cables Brochure Web
Cables Brochure WebCables Brochure Web
Cables Brochure Web
 
Kites
KitesKites
Kites
 
Дмитрий Волох_фулфилмент_Owox_2014
Дмитрий Волох_фулфилмент_Owox_2014Дмитрий Волох_фулфилмент_Owox_2014
Дмитрий Волох_фулфилмент_Owox_2014
 
Oh the Places You'll Go
Oh the Places You'll GoOh the Places You'll Go
Oh the Places You'll Go
 
Hello openstack 2014
Hello openstack 2014Hello openstack 2014
Hello openstack 2014
 

Similar to Oop interfaces

06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classesAnup Burange
 
Interfaces.ppt
Interfaces.pptInterfaces.ppt
Interfaces.pptVarunP31
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxssuser84e52e
 
Interface
InterfaceInterface
Interfacevvpadhu
 
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
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5dplunkett
 
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
 
Interface in Java
Interface in JavaInterface in Java
Interface in JavaDucat India
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classesShreyans Pathak
 
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMU
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMUAutomated Refactoring of Legacy Java Software to Default Methods Talk at GMU
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMURaffi Khatchadourian
 
Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdfKp Sharma
 

Similar to Oop interfaces (20)

06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
Interfaces .ppt
Interfaces .pptInterfaces .ppt
Interfaces .ppt
 
Interfaces.ppt
Interfaces.pptInterfaces.ppt
Interfaces.ppt
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptx
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Interface
InterfaceInterface
Interface
 
Java 06
Java 06Java 06
Java 06
 
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
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5
 
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...
 
Smart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdfSmart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdf
 
Smart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdfSmart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdf
 
Interface in Java
Interface in JavaInterface in Java
Interface in Java
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
javainterface
javainterfacejavainterface
javainterface
 
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMU
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMUAutomated Refactoring of Legacy Java Software to Default Methods Talk at GMU
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMU
 
Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdf
 
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...
 

Recently uploaded

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 

Recently uploaded (20)

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 

Oop interfaces

  • 2. Interfaces  An interface declares (describes) methods but does not supply bodies for them  interface interFaceName{ public void function1(Class1 obj1); public void function2(Class2 obj2); }  All the methods are implicitly public and abstract  You can add these qualifiers if you like, but why bother?  You cannot instantiate an interface  An interface is like a very abstract class—none of its methods are defined  An interface may also contain constants (final variables) which act like constants 2
  • 3. Implementin g an interface  You extend a class, but you implement an interface  A class can only extend (subclass) one other class, but it can implement as many interfaces as you like  Example: class otherClass implements Interface1, Interface2 { //declarations } 3
  • 4. What are interfaces for?  Reason 1: A class can only extend one other class, but it can implement multiple interfaces  This lets the class fill multiple “roles”  This concept could be explained as partial multiple inheritance  In writing Applets, it is common to have one class implement several different listeners  Example: class otherClass extends Applet implements Interface1, Interface2 { //Statements }  Reason 2: You can write methods that work for more than one kind of class 4
  • 5.  instanceof is a keyword that tells you whether a variable “is a” member of a class or interface  For example, if class Dog extends Animal implements Pet {...} Animal fido = new Dog(); then the following are all true: fido instanceof Dog fido instanceof Animal fido instanceof Pet  instanceof is seldom used  When you find yourself wanting to use instanceof, think about whether the method you are writing should be moved to the individual subclasses 5 Instance of
  • 6.  When you implement an interface, you promise to define all the functions it declares  There can be a lot of methods interface KeyListener { public void keyPressed(KeyEvent e); public void keyReleased(KeyEvent e); public void keyTyped(KeyEvent e); }  What if you only care about a couple of these methods? 6 Interfaces again
  • 7.  Solution: use an adapter class  An adapter class implements an interface and provides empty method bodies class KeyAdapter implements KeyListener { public void keyPressed(KeyEvent e) { }; public void keyReleased(KeyEvent e) { }; public void keyTyped(KeyEvent e) { }; }  You can override only the methods you care about  This isn’t elegant, but it does work  Java provides a number of adapter classes 7 Adapter class
  • 8. Vocabulary  abstract method—a method which is declared but not defined (it has no method body)  abstract class—a class which either (1) contains abstract methods, or (2) has been declared abstract  instantiate—to create an instance (object) of a class  interface—similar to a class, but contains only abstract methods (and possibly constants)  adapter class—a class that implements an interface but has only empty method bodies 8