标签:system ack 参数传递 存在 关系 设计 业务 编程 使用场景
package java006; /** * 2017/9/6 * 说明:汽车类 */ public class Car { int num;//轮胎数 String color;//颜色 /** * 运行 */ public void run(){ System.out.print(num +""+color); } }
package java006; /** * 2017/9/6 * 说明: */ public class CarTest { public static void main(String[] args) { Car car = new Car(); car.num = 4; car.color = "红色"; car.run(); } }
package java006; /** * 2017/9/6 * 说明:汽车类 */ public class Car { int num;//轮胎数 String color;//颜色 /** * 运行 */ public void run(){ System.out.print(num +" "+color); } }
package java006; /** * 2017/9/6 * 说明: */ public class CarTest { public static void main(String[] args) { Car car1 = new Car(); car1.num = 4; car1.color = "红色"; Car car2 = new Car(); car2.num = 4; car2.color = "黑色"; car1.run(); car2.run(); } }
package java006; /** * 2017/9/6 * 说明:汽车类 */ public class Car { int num;//轮胎数 String color;//颜色 /** * 运行 */ public void run(){ System.out.print(num +" "+color); } }
package java006; /** * 2017/9/6 * 说明: */ public class CarTest { public static void main(String[] args) { Car car1 = new Car(); car1.num = 4; car1.color = "红色"; Car car2 = car1; car1.run(); car2.run(); } }
package java006; /** * 2017/9/6 * 说明:汽车类 */ public class Car { int num;//轮胎数 String color;//颜色 /** * 运行 */ public void run(){ System.out.print(num +" "+color); } }
package java006; /** * 2017/9/6 * 说明: */ public class CarTest { public static void main(String[] args) { Car car1 = new Car(); new Car().run(); } }
package java006; /** * 2017/9/6 * 说明:汽车类 */ public class Car { int num;//轮胎数 String color;//颜色 /** * 运行 */ public void run(){ System.out.print(num +" "+color); } }
package java006; /** * 2017/9/6 * 说明: */ public class CarTest { public static void main(String[] args) { show(new Car()); } public static void show(Car c){ c.num = 4; c.color = "黑色"; c.run(); } }
package java006; /** * 2017/9/6 * 说明:人类 */ public class Person { private int age; public int getAge() { return age; } public void setAge(int age) { if(age > 0 && age <=200){ this.age = age; } } public void speak(){ System.out.print("我的年龄是:"+age); } }
package java006; /** * 2017/9/6 * 说明: */ public class PersonTest { public static void main(String[] args) { Person p = new Person(); p.setAge(-1); p.speak(); } }
package java006; /** * 2017/9/6 * 说明:人类 */ public class Person { private int age; private String name; public Person(){ } public Person(String name,int age){ this.setName(name); this.setAge(age); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { if(age > 0 && age <=200){ this.age = age; } } public void speak(){ System.out.print("我的姓名是:"+this.name+"我的年龄是:"+age); } }
package java006; /** * 2017/9/6 * 说明: */ public class PersonTest { public static void main(String[] args) { Person p = new Person("张三",26); p.speak(); } }
package java006; public class Person { private String name; private int age; public Person(String name,int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public void speak() { System.out.println(name+" "+age); } }
package java006; public class PersonTest { public static void main(String[] args) { Person p = new Person("哈哈",23); p.speak(); Person p2 = new Person("呵呵",29); p2.speak(); } }
7 单例设计模式
标签:system ack 参数传递 存在 关系 设计 业务 编程 使用场景
原文地址:http://www.cnblogs.com/xuweiweiailixing/p/7482646.html