DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Posts
    6

    writing a definition of a class

    fixed
    Last edited by nymchamp; 12-02-2007 at 10:19 PM.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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 ....

  3. #3
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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

  1. Replies: 26
    Last Post: 12-01-2012, 04:12 AM
  2. writing class to xml
    By Arjun in forum XML
    Replies: 1
    Last Post: 12-27-2005, 02:42 PM
  3. Assembly class
    By Shailesh C.Rathod in forum .NET
    Replies: 2
    Last Post: 03-13-2002, 07:53 PM
  4. WinForm Compile Error
    By Robert in forum .NET
    Replies: 1
    Last Post: 10-24-2000, 11:38 AM
  5. Abstract class
    By Manika in forum Java
    Replies: 1
    Last Post: 09-06-2000, 01:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links