Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-18-2007, 07:21 PM
Member
 
Join Date: Jul 2007
Posts: 35
silvia is on a distinguished road
Error: invalid method declaration
I just wrote my second program to allow you to set and retrieve a username, password, and age for users.

Code:
public class Hello { public User() { } public User(String username, String password, Int age) { usrname = username; usrpass = password; usrage = age; } public void setUserName(String newusrname) { usrname = newusrname; } public void setPassword(String newpass) { usrpass = newpass; } public void setAge(Int newage) { usrage = newage; } public String getUserName() { return usrname; } public String getPassword() { return usrpass; } public Int getAge() { return usrage; } public static void main(String args[]) { usr1 = new User(); usr1.setUserName("UserOne"); usr1.setPassword("PasswordOne"); usr1.setAge(1); usr2 = new User("UserTwo", "PasswordTwo", 2); System.out.println("User 1: " + usr1.getUserName + " " + usr1.getPassword + " " +usr1.getAge); System.out.println("\n"); System.out.println("User 2: " + usr2.getUserName + " " + usr2.getPassword + " " +usr2.getAge); } }
...And here's the errors I get when I compile it...
Code:

Code:
C:\j2sdk1.4.2_11\bin>javac Hello.java Hello.java:2: invalid method declaration; return type required public User() { ^ Hello.java:4: invalid method declaration; return type required public User(String username, String password, Int age) { ^ 2 errors
...I'm pretty sure I understand what these errors mean (return type would be like public String getPassword(), right?), but I just want these ... definitions (I dont know the word yet, new to the vocabulary) of User() to just be used for constructors...I don't want them to return anything.

Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-27-2007, 02:10 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
The term "definition" u refer to, maybe u mean method?
If ur makin a constructor, u gotta name it with the same name as ur class, ur class is Hello, so either u change the method name User into Hello or change the class name Hello into user
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaration asifahmed New To Java 1 04-05-2008 07:38 AM
Error: Non-static method append(char) cannot be referenced from a static context paul Advanced Java 1 08-07-2007 07:05 AM
Error :Invalid path, C:\Program Files\Java\j2re1.4.2_06\bin\javac.exe silvia New To Java 2 07-30-2007 10:55 AM
Error: invalid method declaration; return type required silvia AWT / Swing 1 07-19-2007 03:51 PM
Error : Invalid path, \bin\javac.exe -classpath Ed JCreator 2 07-03-2007 04:40 AM


All times are GMT +3. The time now is 10:15 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org