Interface exercises, teacher student
Working class:
/** encapsulate this function in an interface * / public interface working {void sendad(); / / the methods in the interface are decorated with public abstract by default
}
Student class:
/** define a student class to implement a work interface * a class implements an interface and needs to rewrite the abstract methods in the interface * this class has the functions specified in the interface * / public class student implements working {@ override public void sendad() {system. Out. Println ("student sends flyers...);}
}
Teacher class:
Public class teacher implements working {@ override public void sendad() {system.out.println ("advertising");}
}
Test demo class:
/** working students * / public class demo {public static void main (string [] args) {student stu1 = new student(); stu1. Sendad(); teacher Tc1 = new teacher(); Tc1. Sendad();}}