I use NetBeans 6.7.1 and I’m more used to C and php than Java.
I have a .class file containing “public class myclass”. And in that class I have a private array and a public function getArr returning that array.
In the main class I have this
Object mcl = new myclass();
myclass is found by NetBeans and the above is accepted. But
String[] arr = mcl.getArr();
throws “Cannot find symbol” for getArr.
The file containing that class is in the project and the class found in code completion. But not the function, or I should probably call it a method.
I don’t know if this is Java or NetBeans specific. But how do I get the main class to understand what it can find in my new class? And the compiler?
Am I missing some declaration?
You’re defining mcl as an
Object, which doesn’t have agetArr()method —myclassdoes. You need to do:Then you will be able to refer to all the methods of
myclass.The reason that you’re able to define it as an
Objectis because all classes in Java automatically extendObject, so it is their superclass. But when you define an object asObjectinstead of their actual class, you only get to use the methods provided by superclassObject.