JAVA面向对象高级:static注意事项

package com.itheima.static1;

public class Student {
    static  String schoolName;
    double score;//实例变量
    //1.类方法中可以直接访问类的成员,不可以直接访问实例成员
    public static void printhelloworld(){
        //注意:同一个类中,访问类成员,可以省略类名不写。
        schoolName="heima";
        printhelloworld2();
        //System.out.println(score);  类方法中访问实例变量,报错
        //printPass();  报错的,类方法中不能访问实例方法
        //报错  System.out.println(this);
    }
    //类方法
    public static void printhelloworld2(){

    }
    //实例方法
    //2.实例方法中既可以直接访问类成员,也可以直接访问实例成员
    //3.实例方法中可以出现this关键字,类方法中不能
    public  void printPass(){

        schoolName="12";
        printhelloworld2();
        System.out.println(score);
        ptinPass2();
        System.out.println(this);

    }

    public void ptinPass2(){

    }
}

 

posted @ 2024-03-17 19:58  小彭先森  阅读(4)  评论(0编辑  收藏  举报