Java10一个例子

定义一个计算机类(电脑/笔记本),属性:品牌,型号,颜色
定义一个学生类,属性:学号,姓名,学生有一台笔记本
让其中一名学生去使用一台笔记本

public class Test{
	public static void main(string[] args){
		//创建笔记本对象
		Computer biJiBen = new Computer();
		//手动赋值
		biJiBen.brand = "华硕”;
		biJiBen.style = "asd123";
		biJiBen.color = "black";

		//创建学生对象
		Student zl = new Student();
		//手动赋值
		zl.no = 123;
		zl.name = "zl";
		zl.com = biJiBen;
		
		//zl的笔记本牌子
		System.out.println(zl.com.brand);
		
		//修改牌子
		zl.com.brand = "苹果";

		//原来电脑扔了
		zl.com = new Computer();
		System.out.println(zl.com.brand);//null
	}	
	public class Student{
		string name;
		int no;
		computer com;
	}
	public class Computer{
		string brand;
		string style;
		string color;
	}
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值