aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Accessing enclosing class' super class in inner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Accessing enclosing class Watch "Accessing enclosing class New topic
Author

Accessing enclosing class' super class in inner

prafulla shrikhande
Greenhorn

Joined: Mar 12, 2003
Posts: 4
How do you access enclosing class' super class variables.
I know about <outer>.this.<variable>
Is there such a thing like <outer>.super.<variable>

Look at the code below -

class SuperA {String s1="SuperA";}
class SuperB {String s1="SuperB";}
class A extends SuperA {
String s1="A";
class B extends SuperB { // 1
String s1="B";
void m1() {
System.out.print(this.s1 + ","); // 2
System.out.print(super.s1 + ","); // 3
System.out.print(A.this.s1 + ","); // 4
System.out.print(A.super.s1); // 5
}
}
public static void main (String[] args) {
new A().new B().m1(); // 6
}}

What is the result of attempting to compile and run the program?

a. Prints: B,SuperB,B,SuperB
b. Prints: B,SuperB,A,SuperA
c. Compile-time error at 1.
d. Compile-time error at 2.
e. Compile-time error at 3.
f. Compile-time error at 4.
g. Compile-time error at 5.
h. Compile-time error at 6.
i. Run-time error
j. None of the above
Joe Borderi
Ranch Hand

Joined: Oct 23, 2004
Posts: 151
Have you tried compiling and running the program? In Java you unequivocally should get the same result I do.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Yes, to answer such a question as Is there such a thing like <outer>.super.<variable>? you can compile the code to find out. (Took 30 seconds to do so ).


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing enclosing class' super class in inner