public class Phone {
//品牌
String brand;
//价格
double price;
//尺寸
double size;
//打电话
public void call(String name){
System.out.println("给"+name+"打电话");
}
//玩游戏
public void playGames(){
System.out.println("玩游戏");
}
@Override
public String toString() {
return "Phone{" +
"brand='" + brand + '\'' +
", price=" + price +
", size=" + size +
'}';
}
}
import java.util.Arrays;
public class TestPhone {
public static void main(String[] args) {
//创建对象
Phone p1=new Phone();
Phone p2=new Phone();
//赋值p1
p1.brand = "oppo";
p1.price = 3000;
p1.size = 6;
//赋值p2
p2.brand = "苹果";
p2.price = 5000;
p2.size = 8;
//调用
System.out.println("***********");
p1.call("张三");
p1.playGames();
System.out.println(p1.brand);
System.out.println(p1.price);
System.out.println(p1.size);
System.out.println("***********");
p2.call("李四");
p2.playGames();
System.out.println(p2.brand);
System.out.println(p2.price);
System.out.println(p2.size);
Phone[] arr=new Phone[3];
arr[0]=p1;
arr[1]=p2;
System.out.println(p1);
System.out.println(p2);
System.out.println(Arrays.toString(arr));
}
}