Reputation: 3
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.
Upvotes: 0
Views: 222
Reputation: 2250
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.
Upvotes: 0
Reputation: 94
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.
Upvotes: 0
Reputation: 152294
It is the proper way, but you have repeated x
variable name. Change second x
to z
for example.
Upvotes: 1