JAVA中的成员变量与局部变量

package com.imooc;
//1.定义一个类
public class Telphone {
    //2.属性(成员变量)有什么
    float screen;
    float cpu;
    float mem;
    int var = 30;
    //3.方法干什么
    void call(){
        int var = 40;
        int localVar=0;
        System.out.println("var:"+var);
        System.out.println("loclaVar:"+localVar);
        System.out.println("var:"+var);
        System.out.println("Telphone有打电话的功能!");
    }
    void sendMessage(){
        int localVar=0;
        System.out.println("var:"+var);
        System.out.println("screen:"+screen+" cpu:"+cpu+" mem:"+mem+" Telphone有发短信的功能!");
    }
}
package com.imooc;

public class InitialTelphone {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Telphone phone = new Telphone();
        //phone.sendMessage();
        
        //给实例变量赋值
        phone.cpu = 1.4f;
        phone.mem = 2.0f;
        phone.screen = 5.0f;
        
        //调用对象的方法
        //phone.sendMessage();
        phone.call();
    }

}

 

posted on 2016-04-04 16:33  Mountain's_blog  阅读(274)  评论(0编辑  收藏  举报

导航