-
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
-
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
-
By Miha Markic in forum .NET
Replies: 5
Last Post: 06-19-2006, 09:48 AM
-
By premartha in forum C++
Replies: 3
Last Post: 10-21-2005, 10:06 AM
-
Replies: 3
Last Post: 06-18-2005, 01:13 PM
-
Replies: 2
Last Post: 04-04-2005, 04:31 PM
-
By Morten Dahl in forum .NET
Replies: 3
Last Post: 02-27-2001, 05:39 PM
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