创建一个手机类 ,属性 :品牌、大小、价格
String brand;
Double size;
Double price;
public void call(){
System.out.println("你正在使用"+brand+"品牌的手机");
System.out.println("尺寸是"+size);
System.out.println("价格是"+price);
}
@Override
public String toString() {
return "Phone{" +
"brand='" + brand + '\'' +
", size=" + size +
", price=" + price +
'}';
}
public void playGames(int xiaoshi){
System.out.println(brand+"可以玩"+xiaoshi+"小时");
}
并创建对象,最后输出使用数组输出
public static void main(String[] args) {
Phone p1 = new Phone();
p1.brand = "苹果";
p1.size = 5.5;
p1.price = 6000.8;
p1.call();
p1.playGames(3);
System.out.println("----------------------");
Phone p2 = new Phone();
p2.brand = "华为";
p2.size = 6.5;
p2.price = 8976.67;
p2.call();
p2.playGames(5);
Phone[] arr ={p1,p2};
System.out.println(Arrays.toString(arr));
}