Interfaces In Java

4,317 views

Published on

Published in: Technology, News & Politics
1 Comment
2 Likes
Statistics
Notes
  • I want to download this slide, Even I cant able to view it .
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
4,317
On SlideShare
0
From Embeds
0
Number of Embeds
380
Actions
Shares
0
Downloads
194
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Interfaces In Java

  1. 1. Interfaces Presented By Parag Shah http://www.adaptivelearningonline.net
  2. 2. Agenda <ul><li>Java and multiple inheritance </li></ul><ul><li>Declaring interfaces </li></ul><ul><li>Using interfaces </li></ul>
  3. 3. Java And Multiple Inheritance - 1 <ul><li>Java does not have multiple inheritance </li></ul><ul><li>Inheritance gives us two things </li></ul><ul><ul><li>Code reuse </li></ul></ul><ul><ul><li>Ability to represent the object polymorphically as the super type </li></ul></ul>
  4. 4. Java And Multiple Inheritance - 2 <ul><li>Code reuse in multiple inheritance is risky </li></ul><ul><li>The ability to represent a class polymorphically as a type other than the superclass may be useful </li></ul><ul><li>Interfaces allow the latter but not the former </li></ul>
  5. 5. Interfaces <ul><li>Interfaces are defined with the interface keyword </li></ul><ul><li>Interfaces do not have any code </li></ul><ul><li>All attributes are public static final </li></ul><ul><li>public interface Ignorable { </li></ul><ul><li>public boolean isValid(); </li></ul><ul><li>} </li></ul>
  6. 6. Implementing An Interface <ul><li>Any class can implement an interface </li></ul><ul><li>Use the implements keyword </li></ul><ul><li>A class can implement multiple interfaces </li></ul><ul><li>The class must implement all the methods declared in the interface </li></ul><ul><li>See [biz.adaptivesoftware.examples.interfaces] </li></ul>
  7. 7. Marker Interfaces <ul><li>Some interfaces are used as flags for the JVM </li></ul><ul><ul><li>Cloneable </li></ul></ul><ul><ul><li>Serializable </li></ul></ul><ul><ul><li>SingleThreadModel </li></ul></ul>
  8. 8. Summary <ul><li>Interfaces allow us to polymorphically represent a class as types across inheritance trees </li></ul><ul><li>Interfaces are implemented with the implements keyword </li></ul><ul><li>Do not CREATE interfaces for non standard use such as marker interfaces </li></ul>

×