ちょうきょう666

导航

面向对象

public class Phone {//新建一个类,有打电话的行为也就是方法,有名字和价格的变量
 int price;
 String name;
 public static void main(String[] args) {
  // TODO Auto-generated method stub
 }
 public void call() {
  System.out.println("打电话");
 }
 public void sendMessage() {
  System.out.println("发短信");
 }
}
******************************************************
public class tryPhone {
 public static void main(String[] args) {
  Phone p=new Phone();//实例化类
  System.out.println(p.name);//调用类的属性
  System.out.println(p.price);
  p.call();//调用类的方法
 }
}

posted on 2020-05-22 13:58  ちょうきょう666  阅读(115)  评论(0编辑  收藏  举报