Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax trouble relating to instantiation 1

Status
Not open for further replies.

MissouriTiger

Programmer
Oct 10, 2000
185
US
I would sure appreciate some assistance. Could someone please explain what I'm doing wrong and the correct way to do this?

I have a user class, whose main() method requires 4 arguments. I'm trying to have another class instantiate the user class. But the code won't compile. Their is something about the syntax I don't understand.

Here is the code for my user class main methiod:

public static void main(String uName, String pWord, String fName, String lName)
{
setUsername(uName);
setPassword(pWord);
setFirstName(fName);
setLastName(lName);
}

Here's the method to instantiate:

public MessageSystemUser newSystemUser(
String userName,
String password,
String firstName,
String lastName)
{
return IMUser user = new IMUser(userName, password, firstName, lastName);
}


What is the correct way to do this? If necessary I can post or email the whole classes, they're pretty simple.



 
Classes don't instantiate other classes via the main method. The main method is used as an entry point into your application and is called automatically.

Classes are instantiated via a call to their CTOR, e.g.

MessageSystemUser user = new MessageSystemUser("chudak","wqk31","charles","hudak");

// now you can use the user


here's the class for the MessageSystemUser:

public class MessageSystemUser {
String uname;
String pass;
String fname;
String lname;
...
public MessageSystemUser() {} // no arg ctor
public MessageSystemUser(String uname, String pass, String fname, String lname) {
this.uname = uname;
this.pass = pass;
this.fname =fname;
this.lname = lname;
}
...
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top