public class Student1 {
/**
* 属性
*/
String name; // 名字
int age; // 年龄
String code; // 学号
School position;
int score;//分数
/**
*
* 方法
*/
void listen() {
System.out.println(this.name +",趴在"+position.address+"的屋顶偷窥!");
}
void play(){
System.out.println(this.name+"正在玩农药");
}
void achievement() {
int score=60;
if (score >= 0 && score <= 59) {
System.out.println("你落后太多了,还不努力学习");
} else if (score >= 60 && score <= 90) {
System.out.println("在加把油你可以的");
} else {
System.out.println("很棒");
}
}
String intro() {
return "我叫" + this.name + ",我的学号" + this.code + ",我今年" + this.age + "岁了!";
}
/**
* 构造器
*/
public Student1(String name, int age, String code) {
this.name = name;
this.age = age;
this.code = code;
}
/**
*
* 程序执行入口
*/
public static void main(String[] args) {
//构建一个对象:调用类的构造器
Student1 stu = new Student1("周鹏",18,"2号");
//用对象调用方法
System.out.println(stu.intro());
School s1 =stu.new School();
s1.address ="数字大厦";
stu.position=s1;
stu.achievement();
stu.listen();
stu.play();
/*System.out.println(stu.intro());*/
}
/**
*
* 类和类之间可以相互引用的
*
*/
class School {
String address;// 地址
int telephone;// 电话
String sname;// 名字
}
}
控制台:
我叫周鹏,我的学号2号,我今年18岁了!
在加把油你可以的
周鹏,趴在数字大厦的屋顶偷窥!
周鹏正在玩农药