面向对象的小类型


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岁了!
在加把油你可以的
周鹏,趴在数字大厦的屋顶偷窥!
周鹏正在玩农药
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值