java inner class question
Hello. I am completely new to java. I have C/C++ background. I am quite puzzled at java inner class.
Given the following code:
class Outer
{
private string _name = "outer";
private int _data = 123;
public Outer
{
// It seems these two methods produce same results.
Inner t = new Inner();
Inner t2 = this.new Inner();
t.test();
t2.test();
}
class Inner
{
private string _name = "inner";
public void test()
{
// How to access Outer's _name?
System.out.println(_name);
}
}
}
I have two questions:
1. According to all tutorials, I have use this.new to create an instance of Inner class, but new can do the same. What's the difference?
2. How can Inner's test method access Outer class' _name member variable?