It is the use, square, rectangle, circle, to inherit the interface all interface, to achieve the case of all.
Talk less nonsense, on the code:
Import Java.util.*;interface s{void S ();} Interface C{void C ();} Interface all extends s,c{//This is the multiple inheritance that implements the interface}class Square implements all{private double length = 1;public void S () {System.out. println ("Square area is:" +length*length);} public void C () {System.out.println ("square perimeter is:" +length*4);}} Class Rectangle implements all{private double length =1;private double width = 2;public void S () {System.out.println ("rectangular area is : "+width*length);} public void C () {System.out.println ("Rectangle circumference is:" + (length+width) * *);}} Class Circle implements All{private double r = 1;public void S () {System.out.println ("Circle area is:" +r*r*3.14);} public void C () {System.out.println ("round perimeter is:" +2*r*3.14);}} public class Sandc {public static void result (all a) {A.S (); A.C ();} public static void Main (string[] args) {result (new Square ()); Result (new Rectangle ()); Result (new Circle ());}}
Print out the results, can be tested, can achieve multiple interface multiplexing, effectively implemented, the mechanism of flushing.
This is, Java example, hope to help everyone!
Small red Flag
qq:651134397
Java Advantage interface to implement polymorphic situations, and the use of interfaces to achieve multiple inheritance!