+ 1
inner-class
I'm having a problem calling the inner class, is there a problem in my code? how to call the inner class its methods and attributes? class bullet { class pos { int x; int y; void add(int a, int b) { x += a; y += b; } pos(int a, int b) { x = a; y = b; } } }
2 Answers
+ 2
instantiate the inner class just like you would for a normal class.
public class outer {
private inner innerObject;
public outer()ď˝
innerObject = new inner();
innerObject.dosomething();
ď˝
private class inner ď˝
public inner()ď˝
ď˝
public void dosomething()ď˝
//do something
ď˝
ď˝
ď˝
+ 2
oh, this is Java btw. I don't know how other languages do it.