package com.hanqi; 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; } }
package com.hanqi; public class test { 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()); } }