package thlfive.com; public class ImplmentPreson { public static void main(String[] args) { singer s1=new student("s1"); s1.sing(); s1.sleep(); student student=(thlfive.com.student) s1; student.getName(); singer s2=new teacher("t2"); s2.sing(); s2.sleep(); if ( s2 instanceof dance) { dance d1=(dance) s2; d1.dancing(); d1.sleep(); } } } interface singer{ public void sing(); public void sleep(); } interface dance{ public void dancing(); public void sleep(); } class student implements singer { private String name; public student(String name) { // TODO Auto-generated constructor stub this.name=name; } public void setName(String name) { this.name = name; } public String getName() { return name; } @Override public void sing() { // TODO Auto-generated method stub System.out.println("student in sing "); } @Override public void sleep() { // TODO Auto-generated method stub System.out.println("student in sleep"); } public void study() { System.out.println("studing"); } } class teacher implements singer,dance{ private String name; public teacher(String name) { // TODO Auto-generated constructor stub this.name=name; } public String getName() { return name; } @Override public void dancing() { // TODO Auto-generated method stub System.out.println("teacher in dancing"); } @Override public void sing() { // TODO Auto-generated method stub System.out.println("teacher in sing"); } @Override public void sleep() { // TODO Auto-generated method stub System.out.println("teacher in sleep"); } public void teach() { System.out.println("teaching"); } }
guozhchun
相关分类