标签:int print java 接口 this str 麻将 stat void
package 接口运用;
interface Person{
public void eat();
public void sleep();
public void play();
}
class Student implements Person{
String StudentClass;
public Student(String StudentClass) {
this.StudentClass=StudentClass;
}
public void eat() {
System.out.println(StudentClass+"在食堂吃饭!");
}
public void sleep() {
System.out.println(StudentClass+"在寝室睡觉!");
}
public void play() {
System.out.println(StudentClass+"在操场上玩!");
}
}
class Teacher implements Person{
String TeacherClass;
public Teacher(String TeacherClass) {
this.TeacherClass=TeacherClass;
}
public void eat() {
System.out.println(TeacherClass+"在教师食堂吃饭!");
}
public void sleep() {
System.out.println(TeacherClass+"住在双创楼!");
}
public void play() {
System.out.println(TeacherClass+"在双创楼打麻将");
}
}
class Parents implements Person{
String ParentsClass;
public Parents(String ParentsClass) {
this. ParentsClass= ParentsClass;
}
public void eat() {
System.out.println( ParentsClass+"在城市印象二楼吃饭");
}
public void sleep() {
System.out.println( ParentsClass+"在城市印象住着");
}
public void play() {
System.out.println( ParentsClass+"在城市印象打麻将!");
}
}
public class Dome3 {
public static void main(String[]args) {
Person s = new Student("毛塘铺大学生");
System.out.println("大家好,我在毛塘铺读大学,也就是养老!");
s.eat();
s.sleep();
s.play();
Person t = new Teacher("毛塘铺老师");
System.out.println("大家好,我在毛塘铺教书!");
t.eat();
t.sleep();
t.play();
Person p = new Parents("毛塘铺的取款机");
System.out.println("大家好,我的子女在毛塘铺读书,所以我叫毛塘铺的取款机!");
p.eat();
p.sleep();
p.play();
}
}
标签:int print java 接口 this str 麻将 stat void
原文地址:https://www.cnblogs.com/0929-luoyang/p/10878573.html