在静态方法中访问类的实例成员

 

 

源代码:

package team4;
/**
 *
 * @author 郝子嘉
 *
 */
public class Test {
 int A=5;
 static int B=7;
 public static void show(){
  System.out.println("实例变量A为"+new Test().A);
  System.out.println("静态变量B为"+B);
 }
 public static void main(String[] args){
  Test.show();
  Test t=new Test();
  System.out.println("A为"+t.A);
 }
}

posted on 2019-10-15 19:22  露水清清  阅读(70)  评论(0编辑  收藏  举报

导航