初学对象

南通青鸟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);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值