如何使用对象
使用对象的步骤:
1.创建对象;
类名 对象名=new 类名();//将一个类实例化,得到对象
Telphone phone=new Telphone();
2.使用对象;
引用对象的属性:对象名.属性;
phone.screen=5;
引用对象的方法:对象名.方法名()
phone.sendMessage();
public class Telphone{
float screen;
float cpu;
float mem;
public void call{
System.out.println("可以打电话");
}
public void sendMessage(){
System.out.println("可以发短信"+"cpu:"+cpu+"screen"+screen+"mem:"+mem);
}
}
public class initialTelphone{
public static void main(String[] args){
Telphone phone=new Telphone();
phone.sendMessage();
phone.screen=5.0f;
phone.cpu=4.0f;
phone.mem=2.0f;
phone.sendMessage();
}
}