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) 编辑 收藏 举报