请参阅以下程序和评论:
请告诉我另一个类如何在没有继承的情况下访问受保护的成员?我已经编译并运行了这个程序。
class Sample3
{
final protected String Var1 = "Sample 3 Final Varaible";
final private String Var2 = "Sample 3 Final Varaible";
}//class Sample3
class Sample4
{
public static void main(String args[])
{
Sample3 s3=new Sample3();
//System.out.println(s3.Var2);// Line 12 : this is not accessible as the Private member is being accessed
System.out.println(s3.Var1);//Line 13 : this access the protected member but i have not used inheritance between 2 classes Sample3 and Sample4
}//end of main
}/class Sample4
Var1 是类受保护成员,Var2 是类私有成员。
我在 Sample4 中创建 Sample3 的对象。第 12 行显然是一个错误,但它如何编译第 13 行呢?