什么是成员变量和局部变量
成员变量和局部变量的区别
代码
/javaDemo1/src/com/imooc/Telphone.java
package com.imooc;
public class Telphone {
// 属性(有什么)
float screen;
float cpu;
float mem;
int var;
// 方法,干什么
void call(){
int var = 40;
System.out.println(“var” + var);
System.out.println(“ 打电话 ”);
}
void sendMessage() {
System.out.println(“var” + var);
System.out.println(“screen:”+ screen +”cpu:”+ cpu +” 发短信 ”);
}
}
/javaDemo1/src/com/imooc/InitailTelphone.java
package com.imooc;
public class InitailTelphone {
public static void main(String[] args) {
// TODO Auto-generated method stub
Telphone phone = new Telphone();
// phone.sendMessage();
phone.cpu = 5.0f;
phone.screen = 3.0f;
phone.call();
phone.sendMessage();
}
}