-
writing a definition of a class
fixed
Last edited by nymchamp; 12-02-2007 at 10:19 PM.
-
Only one error?
What is the error which is reported (the words of the message help you LOADS to find the error being reported).
By the way ... where your assignment says that a method "returns" a value, that does not mean that the value is printed to the console. It means that the value is passed back to the calling procedure. In your declaration of the method you need to indicate whether the method is returning nothing (so is "void") or returns a value of the indicated datatype:
void public setScore( int score )
int public getScore()
if the method "returns" a value, there must be a statement which "returns" the value ....
-
your existing statement tells the compiler that you want to create a new object (the "new" command), rather than assign a value to be stored in a memory location your program calls "name" and another at "score".
if you change your assignment statements to:
this.name = name;
and
this.score = score;
your errors should be resolved. (A design point for clarity of a human reading your code: use a different name for your argument to the method than the name of the data field where that value will be stored -- such as newName and newScore.) I have added the "this" self-reference to clarify that you want the object's data fields to refer to the value referenced by the argument.
Similar Threads
-
Replies: 26
Last Post: 12-01-2012, 04:12 AM
-
Replies: 1
Last Post: 12-27-2005, 02:42 PM
-
By Shailesh C.Rathod in forum .NET
Replies: 2
Last Post: 03-13-2002, 07:53 PM
-
Replies: 1
Last Post: 10-24-2000, 11:38 AM
-
Replies: 1
Last Post: 09-06-2000, 01:13 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks