+ 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 Respuestas
+ 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.