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();//呼叫類的方法
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/186228.html
標籤:Java
上一篇:Spring的核心模塊決議
