package package29;
public class C {
// 构造方法:作用:新建对象
public C(){
System.out.println("这是一个构造方法:作用,新建对象");
}
// 有参构造方法,作用,新建对象时运行并传参
public C(String brand,int store,int price){
System.out.println("这是一个有参数构造方法:作用,新建对象");
this.brand=brand;this.store=store;this.price=price;
}
/**计算两个数的和(方法重载) */
void add(int a,int b) {
System.out.println(a+b);
}
/**计算两个数的和(方法重载) */
void add(double a,int b) {
System.out.println(a+b);
}
/**计算两个数的和(方法重载) */
void add(int a,double b) {
System.out.println(a+b);
}
/**计算两个数的和(方法重载) */
void add(double a,double b) {
System.out.println(a+b);
}
// 定义属性--品牌
String brand;
// 内存
int store;
// 价钱
double price;
// 定义方法--call
void call (String num) {
System.out.println(num+"呼叫中。。。。");
}
public static void main(String[] args) {
C bd= new C();
bd.brand="垃圾品牌";
bd.price=999;
bd.store=16;
System.out.println("品牌:"+bd.brand+"内存:"+bd.store+"价格:"+bd.price);
bd.call(bd.brand);
C bd1= new C("华为",32,888);
System.out.println("品牌:"+bd1.brand+"内存:"+bd1.store+"价格:"+bd1.price);
bd1.call(bd1.brand);
bd.add(1,20.2);
}
}
测试结果