1. Multiple inheritance in Java
In C + +, the behavior of an interface that combines multiple classes is called multiple inheritance.
In Java a class can inherit only once, but multiple interfaces can be implemented, note that inheritance must be written before implementation
2. Core reasons for using the interface:
1) in order to be able to transition upward to multiple parent types (and the resulting flexibility)
2) Prevent programmers from creating objects of this class
3. Policy design mode:
Pass different Stringprocessor implementation classes and will do different things separately
Public abstract class Stringprocessor implements Processor {public String name () {return getclass (). Getsimplename (); public abstract string process (Object input);p ublic static string s = "If she weighs the same as a duck, she ' s made of Woo D ";p ublic static void Main (string[] args) {apply.process (New Upcase (), s); Apply.process (New Downcase (), s); Apply.process (New Splitter (), s);}} Class Upcase extends Stringprocessor {public String process (Object input) {//Covariant Returnreturn ((String) input). ToU Ppercase ();}} Class Downcase extends Stringprocessor {public String process (Object input) {return (String) input). toLowerCase ();}} Class Splitter extends Stringprocessor {public String process (Object input) {return arrays.tostring ((String) input). Split (""));}}
Think in Java (vi): interface