hello,
please tell me how to creat an array of an inner cclass;
is this correct??Code java:
class outer { .... .... class inner { ........ ........ } } outer o =new outer(); outer.inner [ ] i = o.new inner[5];
Printable View
hello,
please tell me how to creat an array of an inner cclass;
is this correct??Code java:
class outer { .... .... class inner { ........ ........ } } outer o =new outer(); outer.inner [ ] i = o.new inner[5];
For an array, no.
The correct syntax would be:
Code Java:
outer.inner[] i = new outer.inner[5];
However, if you only wanted a single instance of the inner class, something similar to your syntax would work:
Code java:
outer o = new outer(); outer.inner i = o.new inner();
If you're unsure if something is correct, you can always try it out.
Something I would recommend is to simply declare the inner class static :P
Code Java:
public class Outer { static class Inner {} }
To create a new array it would use the same syntax, but to create a new instance of Inner, you just need to do this:
Code Java:
Outer.Inner i = new Outer.Inner();
thank you very much
prima