Interfaces In Java
-
Upload
parag -
Category
Technology
-
view
4.852 -
download
0
description
Transcript of Interfaces In Java
Interfaces
PresentedBy
Parag Shahhttp://www.adaptivelearningonline.net
Agenda
● Java and multiple inheritance● Declaring interfaces● Using interfaces
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
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
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();}
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]
Marker Interfaces
● Some interfaces are used as flags for the JVM– Cloneable– Serializable– SingleThreadModel
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