gudii9
asked on
inner classes
>>>But what happens if there is no existence of this for the class Outer. To make sense of the rather odd syntax provided for this try to think of the keyword new as used in the above example as belonging to the current insistence of this.
Thus you could change the line that creates the instance of this to read
Inner i = this.new Inner();
Thus if you need to create an instance of Inner from a static method or somewhere else where there is no this object you can use new as a method belonging to the outer class
class Outer{
public class Inner{}
}
class another{
public void amethod(){
Outer.Inner i = new Outer().new Inner();
}
}
I was reading above lines from link
http://www.jchq.net/certkey/0401certkey.htm
did not understand it clearly.
Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
Thus you could change the line that creates the instance of this to read
Inner i = this.new Inner();
Thus if you need to create an instance of Inner from a static method or somewhere else where there is no this object you can use new as a method belonging to the outer class
class Outer{
public class Inner{}
}
class another{
public void amethod(){
Outer.Inner i = new Outer().new Inner();
}
}
I was reading above lines from link
http://www.jchq.net/certkey/0401certkey.htm
did not understand it clearly.
Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
No it does not allow to upload project as a whole - it checks the files inside
annd starts complaining - well try to get to it from the ocode and all libraries
which i mentioned - let me know if you have questions
annd starts complaining - well try to get to it from the ocode and all libraries
which i mentioned - let me know if you have questions
Sorry, I made a mistkae an posted that previous message in the wring window - does not
belong to this question
belong to this question
ASKER
>>So you can treat constructor of the inner class as a method of the outer class.
can you please elaborate on this.
are you saying because of this line
Outer.Inner i = new Outer().new Inner();
please advise
can you please elaborate on this.
are you saying because of this line
Outer.Inner i = new Outer().new Inner();
please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think they summarized it all in the red letters - if you need
to get accesss to the inner class frok another class (not enxclosing outer class but some other class)
then you can use this syntax:
Outer.Inner i = new Outer().new Inner();
So you can treat constructor of the inner class as a method of the outer class.