标签:ble 存在 ora ctr 获取 静态变量 color rac tar
1 class TiXing{ 2 float up,height; 3 static float down; 4 5 TiXing(float x,float y,float z){ 6 up=x; 7 height=y; 8 down=z; 9 } 10 } 11 12 public class ep3_9{ 13 public static void main(String args[]){ 14 TiXing one=new TiXing(1,2,3); 15 System.out.println("one‘s down is:"+one.down); 16 TiXing two=new TiXing(4,5,6); 17 System.out.println("one‘s down is:"+one.down); 18 System.out.println("two‘s down is:"+two.down); 19 20 System.out.println("TiXing‘s down is:"+TiXing.down); 21 } 22 }
实例方法和类方法对实例变量和类变量的访问
实例方法可以对当前对象的实例变量进行操作,也可以对类变量进行操作。实例方法由实例对象调用。
1 class TiXing{ 2 private float up,height; 3 private static float down; 4 5 TiXing(float x,float y,float z){ 6 up=x; 7 height=y; 8 down=z; 9 } 10 public void display(){ 11 System.out.println("up is:"+up+"height is:"+height+"down is:"+down); 12 } 13 public static void change(float number){ 14 down=number; 15 //System.out.println("height:"+height);//出错 16 } 17 } 18 19 public class ep3_9{ 20 public static void main(String args[]){ 21 TiXing one=new TiXing(1,2,3); 22 one.display(); 23 TiXing two=new TiXing(4,5,6); 24 one.display(); 25 two.display(); 26 27 //TiXing.display();//出错 28 one.change(101); 29 one.display(); 30 two.change(102); 31 two.display(); 32 } 33 }
注:此文转自http://www.cnblogs.com/scf141592/p/5726347.html,转载请注明作者出处。
JAVA类与对象---实例变量与类变量的区别,实例方法和类方法的区别
标签:ble 存在 ora ctr 获取 静态变量 color rac tar
原文地址:http://www.cnblogs.com/Devin-Blog/p/6534314.html