I am confused about static class and nested class. Is there any difference to code and use of static & nested class?.

Recommended Answers

All 5 Replies

http://lmgtfy.com/?q=static+and+nested+inner+classes+java

Thanks a lot.

Can you help me on this matter?

I am unable to create an instance of nested class. here is code.

class One {
        class Two {


       }
  }

class MainApp {
    public static void main() {
          One.Two p=new One.Two(); // here is the problem.
   }
}

Two is not static, so it needs an instance of One to be created in. ie One.Two p=new One() . new Two(); Alternatively, declare Two as static

Two is not static, so it needs an instance of One to be created in. ie One.Two p=new One() . new Two(); Alternatively, declare Two as static

adatapost> Thanks JC. I appreciate your knowledge.

My pleasure. J

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.