南通青鸟IT教育103班同学在3教室上崔老师的JAVA课,以对象的方式实现
学校类:package ob.demo01;
public class School {
String name;
String addr;
School(String addr,String name){
this.name=name;
this.addr=addr;
}
}
班级类:
package ob.demo01;
public class Class {
String name;
Class(String name){
this.name=name;
}
}
老师类:
package ob.demo01;
public class Teacher {
String name;
String cname;
Teacher(String name,String cname){
this.name=name;
this.cname=cname;
}
public void work() {
System.out.println(this.name+"的"+this.cname);
}
}
课程类:
package ob.demo01;
public class Course {
String name;
Course(String name){
this.name=name;
}
}
教室类:
package ob.demo01;
public class Classroom {
int num;
Classroom(int num){
this.num=num;
}
}
学生类:
package ob.demo01;
public class Student{
int age;
String name;
public Student(String name,int age){
this.name=name;
this.age=age;
}
public void study() {
System.out.println(this.name+"在学习");
}
}
package ob.demo01;
public class Qnit {
public static void main(String[] args) {
Student stu=new Student("张三",26);
Teacher cui=new Teacher("崔老师","JAVA课");
School qn=new School("南通","青鸟IT教育");
Class ja=new Class("JAVA103班");
Classroom roo=new Classroom(3);
Course cou=new Course("JAVA课");
cui.work();
System.out.println(qn.addr+qn.name+ja.name+"同学在"+roo.num+"教室上"+cui.name+"的"+cui.cname);
}
}