2

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?

1
  • 2
    Try changing it to myclass mc1 = new myclass();. Commented Jan 4, 2010 at 1:04

1 Answer 1

4

You're defining mcl as an Object, which doesn't have a getArr() method -- myclass does. You need to do:

myclass mcl = new myclass();

Then you will be able to refer to all the methods of myclass.

The reason that you're able to define it as an Object is because all classes in Java automatically extend Object, so it is their superclass. But when you define an object as Object instead of their actual class, you only get to use the methods provided by superclass Object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.