Interfaces In Java

8
Interfaces Presented By Parag Shah http://www.adaptivelearningonline.n et

description

 

Transcript of Interfaces In Java

Page 1: Interfaces In Java

Interfaces

PresentedBy

Parag Shahhttp://www.adaptivelearningonline.net

Page 2: Interfaces In Java

Agenda

● Java and multiple inheritance● Declaring interfaces● Using interfaces

Page 3: Interfaces In Java

Java And Multiple Inheritance - 1

● Java does not have multiple inheritance● Inheritance gives us two things

– Code reuse– Ability to represent the object polymorphically as the

super type

Page 4: Interfaces In Java

Java And Multiple Inheritance - 2

● Code reuse in multiple inheritance is risky● The ability to represent a class polymorphically as

a type other than the superclass may be useful● Interfaces allow the latter but not the former

Page 5: Interfaces In Java

Interfaces

● Interfaces are defined with the interface keyword

● Interfaces do not have any code● All attributes are public static final

public interface Ignorable { public boolean isValid();}

Page 6: Interfaces In Java

Implementing An Interface

● Any class can implement an interface● Use the implements keyword● A class can implement multiple interfaces● The class must implement all the methods

declared in the interface● See [biz.adaptivesoftware.examples.interfaces]

Page 7: Interfaces In Java

Marker Interfaces

● Some interfaces are used as flags for the JVM– Cloneable– Serializable– SingleThreadModel

Page 8: Interfaces In Java

Summary

● Interfaces allow us to polymorphically represent a class as types across inheritance trees

● Interfaces are implemented with the implements keyword

● Do not CREATE interfaces for non standard use such as marker interfaces