- Interfaces are like 100-percent abstract classes.
- Interfaces methods are by default public and abstract - however the explicit declaration is optional.
- Interfaces can be implemented by any class.
- Interfaces can have constants.
- Interface constants are implicitly public, static and final.
- An interface can have only abstract methods - no concrete methods are allowed.
- Interfaces cannot extend a class or implement any other interface.
- However, Interfaces can extend as many interfaces as possible.
- As you know, there is no multiple inheritance allowed in Java i.e a class cannot extend more than one class BUT a class can implement multiple interfaces.
- The class implementing an interface can itself be abstract.
- An abstract implementing class need not have to implement the interface methods, however the non-abstract (concrete) class MUST implement the methods if it implements an interface.
public abstract Sizeable{ // use of public modifier is optional, if you don't want default access
public abstract toDo(); // Note the abstract methods always end with a ; instead of {}
public abstract doThis();
}
class Baloon implements Sizeable {}
public class Tyre mplements Sizeable {}
No comments:
Post a Comment