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.
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:

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.







0
for_yanCommented:
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
0
for_yanCommented:
Sorry, I made a mistkae an posted that previous message in the wring window - does not
belong to this question
0
gudii9Author Commented:
>>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
0
for_yanCommented:

Yes, because of this line.

if Outer had a method say called myMethod, you
could call it in this way:

SomeResult result = (new Outer()).myMethod();

and this is similar to that line
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.