zoukankan      html  css  js  c++  java
  • 成员变量(对象共享类变量及常量的用法)Example4_4//Example4_5

    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 arg[]){
      Lader.bottom=60;
      Lader laderOne,laderTwo;
      System.out.println("现在所有Lader对象的bottom都是:"+Lader.bottom);
      laderOne=new Lader();
      laderTwo=new Lader();
      System.out.println("laderOne的bottom:"+laderOne.getBottom());
      System.out.println("laderTwo的bottom:"+laderTwo.getBottom());
      laderOne.setAbove(11);
      laderTwo.setAbove(22);
      laderTwo.setBottom(100);
      System.out.println("现在所有Lader对象的bottom都是:"+Lader.bottom);
      System.out.println("laderOne的above:"+laderOne.getAbove());
      System.out.println("laderTwo的above:"+laderTwo.getAbove());
     }
     
     
    }

    如果成员变量被final修饰,就被叫做常量。(下例为常量的用法)

    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);
     }
    }

  • 相关阅读:
    Django之搭建学员管理系统
    数据库查询操作(fetchone,fetchall)
    HTTP 方法:GET与 POST
    初识django框架
    Memcached的批量删除方案总结
    centos5.5 下面 lnmp环境遇到的小问题
    CentOS 5.5 --学习(1)
    HTTP请求方法及响应码详解(http get post head)
    codeigniter注意点
    htaccess 伪静态的规则
  • 原文地址:https://www.cnblogs.com/wangchunmeix/p/2974165.html
Copyright © 2011-2022 走看看