1、面向对象的设计方式应该说所有的设计思路来源实现生活。
2、你在现实生活中可以理解的概念,都可以完整的反应到面向对象之中。
3、引用是实现两个不同类型之间相关联的主要手段。
列:
class Car{
String pname;
String pname;
public Car(String pname) {
this.pname = pname;
}
this.pname = pname;
}
public String getPname() {
return "车的编号:"+pname;
}
return "车的编号:"+pname;
}
public Number number;
public Number getNumber() {
return number;
}
public void setNumber(Number number) {
this.number = number;
}
}
class Number{
int imd;
String name;
Number child;
public Number(int imd, String name) {
this.imd = imd;
this.name = name;
}
public String print(){
return "编号:"+imd+"姓名:"+name;
}
public Number getChild() {
return child;
}
return "编号:"+imd+"姓名:"+name;
}
public Number getChild() {
return child;
}
public void setChild(Number child) {
this.child = child;
}
this.child = child;
}
public Car car;
public Car getCar() {
return car;
}
public void setCar(Car car) {
this.car = car;
}
}
public class Hpp {
public Car getCar() {
return car;
}
public void setCar(Car car) {
this.car = car;
}
}
public class Hpp {
public static void main(String[] args) {
Number number = new Number(1,"吴灿");
Number chd = new Number(2,"王凯");
Car car = new Car("兰博基尼");
Car cc = new Car("法拉利");
number.setCar(car);
car.setNumber(number);
chd.setCar(cc);
number.setChild(chd);
System.out.println(car.getNumber().print());
System.out.println(number.getCar().getPname());
System.out.println(number.getChild().print());
System.out.println(number.getChild().getCar().getPname());
Number number = new Number(1,"吴灿");
Number chd = new Number(2,"王凯");
Car car = new Car("兰博基尼");
Car cc = new Car("法拉利");
number.setCar(car);
car.setNumber(number);
chd.setCar(cc);
number.setChild(chd);
System.out.println(car.getNumber().print());
System.out.println(number.getCar().getPname());
System.out.println(number.getChild().print());
System.out.println(number.getChild().getCar().getPname());
}
}