+ 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; } } }

19th Sep 2017, 12:55 AM
John Lemuel Lipio
John Lemuel Lipio - avatar
2 Antworten
+ 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 } } }
19th Sep 2017, 2:14 AM
Gao Xiangshuai
Gao Xiangshuai - avatar
+ 2
oh, this is Java btw. I don't know how other languages do it.
19th Sep 2017, 2:16 AM
Gao Xiangshuai
Gao Xiangshuai - avatar