I am extending inner class in other inner sub class class but enclosing class of the inner subclass is not a subclass of Outer and i am passing explicit reference to an object of Outer to a constructor of Inner subclass. Problem is my member variables of inner subclass are not getting initialized and also initialization block is not executed even though object of inner subclass class is created successfully Can any one tell me what is wrong in this code code: -------------------------------------------------------------------------------- public class outer { public class inner { } } ------------------------------------------------------------------------- public class eouter { public class iinner extends outer.inner { int z= 10; {System.out.println("I am called");} public iinner(outer out) { out.super(); } }public static void main(String args[]) {outer out = new outer();eouter eout = new eouter();iinner inn = eout.new iinner(out);System.out.println("z = " + inn.z);}} -------------------------------------------------------------------------------- I am expecting out put like I am called z = 10 but i am getting z = 0 only
Son Le
Greenhorn
Joined: Jan 15, 2001
Posts: 21
posted
0
Shakti, I'm getting what you expected. I'm called. z=10 I'm using Java1.2 Hungson Le
-LHS
Suresh Selvaraj
Ranch Hand
Joined: Nov 14, 2000
Posts: 104
posted
0
Hi, I tried your code and is giving the output you expected!!! Here it is : class outer { public class inner { } }
public class eouter { public class iinner extends outer.inner { int z= 10; { System.out.println("I am called"); }
public iinner(outer out) { out.super(); } } public static void main(String args[]) { outer out = new outer(); eouter eout = new eouter(); iinner inn = eout.new iinner(out); System.out.println("z = " + inn.z); } } "I am called" z=10 - Suresh Selvaraj, [ www.jtips.net ]
Suresh Selvaraj, (author of JQuiz)<br />SCJP2<br /><a href="http://www.decontconsulting.com" target="_blank" rel="nofollow">www.decontconsulting.com</a>
Ishaan Mohan
Ranch Hand
Joined: Jan 20, 2001
Posts: 115
posted
0
I am not able to understand the flow of this code. Can anybody please explain it to me.