手机
package hello; public class Phone1 { public static void main(String[] args){ Phone iphone6=new Phone(); iphone6.setColor("土豪金"); iphone6.call("10086"); //新的构造 Phone huawei=new Phone("华为","1234"); System.out.println("品牌="+huawei.getPinPai()+"号码"+huawei.getHaoma()); } }
package hello; public class Phone { private String pinPai;//品牌 public String getPinPai() { return pinPai; } private String haoma;//号码 public String getHaoma() { return haoma; } private String color;//颜色 public String getColor() { return color; } public void setColor(String color) { this.color = color; } //构造方法,构造对象的时候调用的方法 public Phone (){ System.out.println("调用默认的构造方法"); } //新的构造方法 public Phone (String pinPai,String haoma){ this.pinPai=pinPai; this.haoma=haoma; } public int call (String haoma){ System.out.println("拨打的号码为"+haoma); int thsj= 3; return thsj; } }