|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Java
Hey, i'm relatively new to java, i understands the bases of it
my problem is this... how do i use somethng like "Users[] users"? what do i need to do to make the following code work?? public class Users { public String Account() { Users[] users; users = new Users[3]; users[0] = "user"; users[1] = 1; users[2] = "admin"; } } any help is appricated thanks |
|
#2
|
|||
|
|||
|
Hi,
1. i don't see any constructors 2. you are declaring variables with the same name as the class? 3. you are not returning any string in your Account method. http://galileo.spaceports.com/~ibidris/ |
|
#3
|
||||
|
||||
|
in your code i see some errors:
- the Account method is not returning any string at the end: you can change the return type to void or add a return statement if you need it. - the Users array is filled with Strings and one int: this is wrong 'cause if you declare the array to be of type Users you can fill it ONLY with Users objects. a constructor for a class is not needed 'cause Java automatically creates an empty contructor if none is supplied. Also there is nothing wrong with naming fields with the same name of the class, but keep in mind that they cannot be exactly the same. You cannot this: Code:
Users[] Users = new Users[3]; but this is right (as you wrote): Code:
Users[] users = new Users[3]; |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|