Maison >Java >javaDidacticiel >提高代码复用性
提高代码复用性
package car; public class Car { String color; int number; void run(){ System.out.println(color+"::"+number); } } class carDemo { public static void main(String[] args) { Car c = new Car(); show(c); } /* * 封装功能 * Car c = new Car(); * Car c1 = new Car(); * */ public static void show(Car cc) { cc.color = "red"; cc.number = 4; cc.run(); } }