关于 "static" 关键字的那点事

 方法的调用的两种方法



     * 1.对象调用 如:对象.方法()

     * 2.类的调用 方法所在类的名字.方法(实参) 前提:这个被调用的方法必须使用static修饰

     * 3.static 是所有对象共享的
     * 4.static 主要用于工具类和功能时

     * 5 没有使用static修饰的方法或字段,属于对象---》实例成员
     * 6.使用static 修饰的方法或字段,属于类  ---》》类成员


/**
 * Created by Administrator on 2014-10-26.
 */
public class infoClass {
    private int a;
    private int b;
    private int c;

    infoClass() {
    }

    ;

    public infoClass(int a, int b, int c) {

    }
    //static 随着类的加载加载
    //优先于对象存在

    /**
     * 方法的调用
     * 1.对象调用 如:对象.方法()
     * 2.类的调用 方法所在类的名字.方法(实参) 前提:这个被调用的方法必须使用static修饰
     * static 是所有对象共享的
     * static 主要用于工具类和功能时
     *
     */
    public class Cellphone {
        void showInfo() {
            infoClass infoClass = new infoClass();

        }

        /**
         * 没有使用static修饰的方法或字段,属于对象---》实例成员
         * 使用static 修饰的方法或字段,属于类  ---》》类成员
         */
        class Person{
            String Name;
            int aga;
            public   void main(){
                System.out.println();
            }
        }
    }

}


版权声明:本文为博主原创文章,未经博主允许不得转载。(转载请注明出自 AllenCoder)

原文地址:https://www.cnblogs.com/allencoder/p/4830756.html