Program Liu Congcong Public interface sing {public static final string eyecolor= "BLACK";p ublic Void sleep ();p ublic void sing ();} public interface print {public static final string sex= "Woman";p ublic Void print ();p ublic 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 student of the name" +name+ "is a person who likes to sing");} 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 (+); t1.sing (); t1.sleep (); print p1= (Print) t1; //(object type Cast) p1.print (); p1.eat (); teacher t2= (Teacher) t1; t2.info ();}}
This article is from the "secret of Technology" blog, so be sure to keep this source http://liucongcong.blog.51cto.com/11527480/1774876
The implementation of abstract methods in the Java applet---interface (solves the problem that the Java language cannot inherit more)