成员变量练习

4-4两个Lader共享bottom

class Lader{

   double above,height;

   static double bottom;

   void setAbove(double a){

      above=a;

  }

   void setBottom(double b){

      bottom=b;

   }

   double getAbove(){

      return above;

}

   double getBottom(){

      return bottom;

}

}

class Example4_4{

   public static void main(String args[]){

      Lader.bottom=60;

  Lader laderOne,laderTow;

  System.out.println("现在所有Lader对象的bottom都是"+Lader.bottom);

  laderOne=new Lader();

  laderTow=new Lader();

  System.out.println("laderOnebottom:"+laderOne.getBottom());

  System.out.println("laderTowbottom:"+laderTow.getBottom());

  laderOne.setAbove(11);

  laderTow.setAbove(22);

  laderTow.setBottom(100);

  System.out.println("现在所有Lader对象的bottom都是"+Lader.bottom);

  System.out.println("laderOneabove:"+laderOne.getAbove());

  System.out.println("laderTowabove:"+laderTow.getAbove());

  }

  }

4-5常量的用法

class Tom{
   final int MAX=100;
   static final int MIN=20;
}
public class Example4_5{
   public static void main(String args[]){
       System.out.println(Tom.MIN);
    Tom cat=new Tom();
    int x=0;
    x=Tom.MIN+cat.MAX;
    System.out.println(x);
    }
}

posted on 2013-03-24 16:24  jixiuyan  阅读(130)  评论(0)    收藏  举报