Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print the String s in 2

Status
Not open for further replies.

IPOz

Programmer
Jul 11, 2001
109
CN
The source code is as below:
public class MOuter {
private String s = "private String of MOuter"; //---1

public static void main(String[] args) {
MOuter mo = new MOuter();
mo.go();
}

public void go() {
final String s = "local final String of MOuter's go()"; //---2

class MInner {
private String s = "private String of MInner"; //---3
public void go() {
System.out.println(this.s); //3's s
System.out.println("1:" + MOuter.this.s); //1's s
System.out.println(???); //2's s
}
}

MInner mi = new MInner();
mi.go();
}
}

How can i print 2's String s?
IPO_z@cmmail.com
Garbage in,Garbage out
 
From all I've read you can't. The local variable s in go() is hidden by the member variable s in MInner. There is no 'super' here.
 
If you replace 2's s with ss or any different name,then you can use it directly within MInner.go. So it is not violating the access privilege!

Regards! IPO_z@cmmail.com
Garbage in,Garbage out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top