1、方法类
public class Phone {
String brand;
double price;
double size;
public void hm (int call) {
System.out.println("手机品牌是:"+brand);
System.out.println("手机价格是:"+price);
System.out.println("手机尺寸是:"+size);
System.out.println("我在给"+call+"打电话");
}
public void yx (String playGames) {
System.out.println("我在玩"+playGames+"游戏");
}
@Override
public String toString() {
return "\n手机{" +
"品牌='" + brand + '\'' +
", 价格=" + price +
", 大小=" + size +
'}';
}
}
2、对象类:
import java.util.Arrays;
public class dx {
public static void main(String[] args) {
Phone p1 = new Phone();
p1.brand = "华为";
p1.price = 30000.0;
p1.size = 65;
p1.hm(15023);
p1.yx("wz");
System.out.println("***************************");
Phone p2 = new Phone();
p2.brand = "苹果";
p2.price = 55.5;
p2.size = 67;
p2.hm(65);
p2.yx("王者");
Phone[] arr = new Phone[2];
arr[0] = p1;
arr[1] = p2;
System.out.println(Arrays.toString(arr));
}
}