Public interface Sing {
public static final String eyecolor= "Black";
public void sleep ();
public void Sing ();
}
Public interface Print {
public static final String sex= "woman";
public void print ();
public void eat ();
}
public class Student implements sing{
String name;
Public Student (String name) {
This.name=name;
}
Public String GetName () {
return name;
}
public void sleep () {
System.out.println ("Student is Sleeping");
}
public void Sing () {
System.out.println ("Student is SingSong");
}
public void All () {
System.out.println ("The name" +name+ "student is a person who likes singing");
}
}
public class teacher implements sing,print {
int age;
Public teacher (int age) {
This.age=age;
}
Public int getage () {
return age;
}
Public void print () {
System.out.println ("Teacher is print");
}
Public void eat () {
System.out.println ("teacher is eating");
}
Public void sleep () {
System.out.println ("teacher is sleeping");
}
public void sing () {
System.out.println ("Teacher is singsong");
}
Public void info () {
System.out.println ("This" +age+ "old teacher can sing and draw");
}
}
public class Test {
public static void Main (string[] args) {
Student s1=new Student ("liqing");
S1.sleep ();
S1.sing ();
S1.all ();
Sing t1=new Teacher (25);
T1.sing ();
T1.sleep ();
Print p1= (print) T1; (Object type Cast)
P1.print ();
P1.eat ();
Teacher t2= (Teacher) T1;
T2.info ();
}
}
The implementation of abstract methods in the Java applet---interface (solves the problem that the Java language cannot inherit more)