Saturday, 15 February 2014

java - extending an interface instead of implementing it -


An interface definition (see below) confused me:

  Public intangible interface Cursor {// hide hide} public abstract interface parcel {// hide details} public interface foo & lt; T extended bar & gt; Increases cursor, parcelable {details omitted for short description};   
  1. I thought that Java does not have multiple succession, so no class can expand more than one class
  2. On the other hand, a class / interface can apply multiple interfaces. So why does apply instead of extension ?

      Interface natural number {zero increment (); Default zeros add (int n) {for (int i = 0; i & lt; n; i ++) {increment (); }}} Class natural number implementation natural number {private int n = 0; @ Override public zero increase () {n ++; }}   

    This is present to allow you to ignore the implementation of some methods, whenever you will possibly be able to apply a "better" version to them / as needed. For example:

      class high effect natural number implementation natural number {private int n = 0; @ Override public zero increase () {n ++; } @ Override Public Zero Addition (int n) {this.n + = n; }}    

No comments:

Post a Comment