public class test3
{
private int m;//私有变量(不管是实例变量还是类变量)
int fun()
{
m = 11;
return m;
}
private int func()//私有方法(不管是实例方法还是类方法)
{
return m;
}
public static void main(String[] args)
{
test3 s= new test3();
int h = s.m = 100;//私有变量只能通过本类中的对象来访问,非本类的不可以
int n = s.func();//私有方法也只能通过本类中创建的对象来访问,非本类的不可以
int k = s.fun();
System.out.println("h = " + h + " n = " + n + " k = " + k);
}
}