0

I want to ask what is the proper way to define an array as argument in class constructor ?

for example

public class example {
    int x;
    int y;
    String [] x = new Array [5];

    public example(int x, int y, String [] x){
    etc etc etc.

Is String [] x is written right ? because netbeans is giving an error however i change it.

3
  • 1
    ARe you sure it's giving you error at that location. It seems like you would get the error a couple of line behind. Commented Jan 30, 2013 at 15:30
  • FIXED. mistakenly putted "Array" . Commented Jan 30, 2013 at 17:38
  • There were a bunch of typographical mistake in your question which were all edited away. I rolled it back so that the answers make sense now. Commented Mar 30, 2015 at 20:36

3 Answers 3

1

It is the proper way, but you have repeated x variable name. Change second x to z for example.

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

1 Comment

oh sorry lol, was just doing a quick example. so i was doing it right .. it's weird that netbeans kept underlining it with red
0

You can define the array as such:

 String[] x = new String[5];

edit: and make sure you don't repeat variable names so change x to something else as you have defined x as an int already.

Comments

0
String [] x = new Array [5];

should be

String [] x = new String[5];

And your variable x is a duplicate. You should change that.

Also, class names start with an upper case letter by convention.

You should also work on your formatting / indent for easier readable code.

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.