可以把内部类,看成是外部类的成员。所以在main()函数中 ,需要先将外部类实例化,再通过实例化对象调用内部类,为内部类实例化。
2018-03-11
想要为设置的属性全部创建setter和getter方法,可以:
1、在Eclipse里,编程区空白地方,右键找到 source
2、然后在source里扎到Generate ->getters and setters -> select all
3、这样就可以为封装的属性全部创建setter和getter了。
1、在Eclipse里,编程区空白地方,右键找到 source
2、然后在source里扎到Generate ->getters and setters -> select all
3、这样就可以为封装的属性全部创建setter和getter了。
2018-03-11
this.name 为当前类的name的值,等同于Inner.this.name;
HelloWorld.this.name则访问外部类的name值
HelloWorld.this.name则访问外部类的name值
2018-03-09
最赞回答 / qq_卡萨布兰卡的脆皮甜筒_0
可以引入接口概念。java父类只能单继承,但接口可以多个继承。可以考虑在你的代码Car类中仅仅只加入name和price两个变量,创建载人Human和载物Cargo的两个接口,载人客车继承Car同时继承Human接口,货车继承Car的同时,继承Cargo接口,皮卡车继承Car并同时继承Human和Cargo两个接口,这样可以实现你所说的分别输出。
2018-03-09