package com.use; public class AccessModifier { public int n1 = 100; protected int n2 = 200; int n3 = 300; private int n4 = 400; public void m1() { System.out.print("n1=" + n1 + " " + "n2=" + n2 + " " + "n3=" + n3 + " " + "n4=" + n4); } } class Test{ public void myTest(){ AccessModifier accessModifier = new AccessModifier(); int n1 = accessModifier.n1; int n2 = accessModifier.n2; int n3 = accessModifier.n3; // 同一包下的不同类 不能直接访问private // int n4 = accessModifier.n4; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)