今天面向对象第一天比较难理解,代码在敲一遍
class Demo1
{
public static void main(String[] args)
{
Phone p=new Phone();
p.brand="大哥大";
p.price=19888;
System.out.println(num);
System.out.println(p.brand+"-------"+p.price);
p.call();
Phone p1=new Phone();
p.brand="诺基亚";
p.price=3500;
System.out.println(p.brand+"-----"+p.price);
p1.playGame();
}
}
class Phone{
String brand ;
int price;
public void sendMessage(){
int num=10;
System.out.println("发短信");
}
public void call(){
System.out.println("打电话");
}
public void playGame(){
System.out.println("玩游戏");
}
}
|
|