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

did not understand it clearly.

 Any ideas, resources,sample code,links,  highly appreciated. thanks in advance.
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.


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.

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

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

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

From novice to tech pro — start learning today.