Java applets-Implementation of abstract methods in interfaces (solving the problem that JAVA cannot inherit more) and java applets
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 ("Student named" + name + "is a singer ");
}
}
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 + "year 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; // (forced conversion of object types)
P1.print ();
P1.eat ();
Teacher t2 = (Teacher) t1;
T2.info ();
}
}