zoukankan      html  css  js  c++  java
  • static 修饰符

    package com.xuexi;
    //static 修饰符,用来修饰类方法和类变量
    //静态变量:static 关键字用来声明独立于对象的静态变量,无论一个类实例化多少对象,它的静态变量只有一份拷贝。 静态变量也被称为类变量。局部变量不能被声明为 static 变量。
    //静态方法:static 关键字用来声明独立于对象的静态方法。静态方法不能使用类的非静态变量。静态方法从参数列表得到数据,然后计算这些数据。
    public class Test1 {
    private static int numInstances = 0;
    protected static int getCount(){
    return numInstances;
    }
    private static void addInstance(){
    numInstances++;
    }
    Test1() {
    Test1.addInstance();
    }

    public static void main(String[] args) {
    System.out.println("Starting with "+Test1.getCount()+" instances");
    for(int i = 0; i<500;++i){
    new Test1();
    }
    System.out.println("Created "+Test1.getCount()+" instances");
    }
    }
  • 相关阅读:
    tyvj1061Mobile Service
    POJ3666序列最小差值
    POJ2279杨氏矩阵+钩子定理
    POJ2127 LICS模板
    codevs2189数字三角形(%100)
    qhfl-7 结算中心
    qhfl-6 购物车
    qhfl-5 redis 简单操作
    qhfl-4 注册-登录-认证
    qhfl-3 Course模块
  • 原文地址:https://www.cnblogs.com/husband/p/14254523.html
Copyright © 2011-2022 走看看