DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2006
    Posts
    1

    Question Initializing strings to zero value in a Constructor

    Hi,
    I'm struggling to understand how to initialize a string to zero value within the constructor. I have created mutator method and accessor method to display the string entered by user, however when using the accessor method it keeps displaying a null value.

    class Book
    {
    // The fields.
    private String author;
    private String title;
    private int pages;
    private String refNumber = null;

    public void setRefNumber(String ref)
    {
    ref = refNumber;
    }

    /**
    * returns the reference number
    */

    public String getRefNumber()
    {
    return refNumber;
    }

    Any help would be greatly appreciated

    Many thanks

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    In an assignment statement, the variable which is being assigned a value is the left hand side of the assignment operator, while the value being assigned is on the right. Therefore, your statement should be

    refNumber = ref;

Similar Threads

  1. Replies: 5
    Last Post: 06-19-2006, 09:48 AM
  2. Replies: 3
    Last Post: 10-21-2005, 10:06 AM
  3. Need help with writing a constructor!
    By Falcone in forum Java
    Replies: 3
    Last Post: 06-18-2005, 01:13 PM
  4. Copy Constructor
    By dubbu in forum C++
    Replies: 2
    Last Post: 04-04-2005, 04:31 PM
  5. C# constructor
    By Morten Dahl in forum .NET
    Replies: 3
    Last Post: 02-27-2001, 05:39 PM

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