看了下大家写的代码,觉得有些同学有些地方写的不太好,不够简洁 ,也把自己写的实现贴到手记里了,欢迎一起探讨,共同进步。
另外,我觉得这个项目没必要使用接口,用了接口会增加很多不必要的工作量(类里面要实现接口的方法,要添加更多的类),有一种好的实现就够了。
手记链接:http://www.imooc.com/article/10181
另外,我觉得这个项目没必要使用接口,用了接口会增加很多不必要的工作量(类里面要实现接口的方法,要添加更多的类),有一种好的实现就够了。
手记链接:http://www.imooc.com/article/10181
2016-07-07
封装是指将类的某些信息隐藏在类的内部,不允许外部程序直接访问,而是通过该类提供的方法来实现对隐藏信息的操作和访问。
2016-07-07
public class Test {
public static void main(String[] args) {
Vehicle o2 = new Bus();
Vehicle o3 = new Ferry();
Vehicle o4 = new Plane();
o2.method("Bus", "land");
o2.passenger(40);
o3.method("Ferry", "sea");
o3.passenger(200);
o4.method("Plane", "air");
o4.passenger(300);
}
}
public static void main(String[] args) {
Vehicle o2 = new Bus();
Vehicle o3 = new Ferry();
Vehicle o4 = new Plane();
o2.method("Bus", "land");
o2.passenger(40);
o3.method("Ferry", "sea");
o3.passenger(200);
o4.method("Plane", "air");
o4.passenger(300);
}
}
2016-07-06
Vehicle.java
public class Vehicle {
public void method(String name,String way) {
System.out.println(name+"'s function is:"+way);
}
public void passenger(int account) {
System.out.println("Passenger account = "+account);
}
}
public class Vehicle {
public void method(String name,String way) {
System.out.println(name+"'s function is:"+way);
}
public void passenger(int account) {
System.out.println("Passenger account = "+account);
}
}
2016-07-06
http://www.imooc.com/article/10111
先不区分载人载重这两种状态,尽量使用封装、继承的方式实现系统功能。有3个类,50行代码。
等待研究完接口后在制作接口版本
先不区分载人载重这两种状态,尽量使用封装、继承的方式实现系统功能。有3个类,50行代码。
等待研究完接口后在制作接口版本
2016-07-06