1 class Demo2_Phone{ 2 3 4 public static void main(String[] args) { 5 6 7 Phone p1 = new Phone(); 8 p1.setPrice(10); 9 System.out.println(p1.getPrice()); 10 } 11 } 12 13 class Phone{ 14 String brand; 15 private int price; 16 17 public void call(){ 18 System.out.println("call"); 19 } 20 21 public void sendMessage(){ 22 System.out.println("sendMessage....."); 23 } 24 25 public void setPrice(int price){ 26 if(price<90&& price>80){ 27 this.price = price; 28 }else{ 29 System.out.println("no price"); 30 } 31 32 } 33 34 public int getPrice(){ 35 return price; 36 } 37 }
时间: 2024-12-16 06:04:58