aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from danchisholm 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 "Question from danchisholm" Watch "Question from danchisholm" New topic
Author

Question from danchisholm

deepu Bhalotia
Ranch Hand

Joined: Apr 19, 2005
Posts: 39
http://www.danchisholm.net/july21/mybook/chapter11/exam1.html

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
}}

Can you explain me about line number-6...
S.L.Narayanan
Ranch Hand

Joined: Apr 01, 2005
Posts: 431


Hi...This is quite simple...they are creating an object for inner class and they are calling a method present inside the inner class.

new A().new B() will create an object for B. So new A().new B().m1(); will invoke method m1().

Inside that they are printing 4 things...
(1). this.s1 which means s1 present in the class B..--->B
(2). super.s1 which means s1 in the class SuperB.--->SuperB
(3). A.this.s1 which points to s1 in the class A --->A
(4). A.super.s1 which points to s1 in the class SuperA--->SuperA

So output will be B, SuperB, A, SuperA. Clear???


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, NEXT--->IBM XML
 
 
subject: Question from danchisholm