Explain the rules for tostring() methods, JAVA Programming

Assignment Help:

Explain the Rules for toString() Methods ?

toString() methods should return a single line of text that does not contain any carriage returns or linefeeds.
toString() methods are primarily for debugging.
toString() should not do a lot of fancy processing. toString() methods should be fast.

The string returned through toString() should contain the name of the class, and names and values of the fields which represent the state of the object, unless there are an excessive number of such fields, in that case only the most important should be returned.

A better Car toString() method would be:
public String toString() {
return "[Car: plate=" + this.licensePlate
+ " speed=" + this.speed + "; MaxSpeed=" + this.maxSpeed +"]");
}
These rules are conventions, not needs of the language.


Related Discussions:- Explain the rules for tostring() methods

Function and array in java script, Specifications 1. readNumberOfEntri...

Specifications 1. readNumberOfEntries → This function will ask the user for a value greater than or equal to two. The function will keep asking values as long as the user prov

Create a usercontrol called loginpasswordusercontrol, (Login User Control) ...

(Login User Control) Create a UserControl called LoginPasswordUserControl that contains a Label (loginLabel) that displays string "Login:", a TextBox (loginTextBox), where the user

Boggle Game, any one out there with Boggle Source code?......i really need ...

any one out there with Boggle Source code?......i really need it guys please.

Conditional Execute, Write a program that prompts for two people’s birthday...

Write a program that prompts for two people’s birthdays (month and day), along with today’s month and day. The program should figure out how many days remain until each user’s birt

Android Development Project, Task I have an Android mobile app project tha...

Task I have an Android mobile app project that I''m trying to get profiles to transfer by connecting to a server at 23.23.175.213 port 1337. I have to send a json string to the se

Talent agency system, Talent agencies like ICM, CAA and Paradigm represent ...

Talent agencies like ICM, CAA and Paradigm represent writers, directors and actors (among other talent).  These agencies take in hundreds of millions of dollars a year collecting 1

What are the services given by the rmi object, RMI Object services: In...

RMI Object services: In addition to its remote object architecture, RMI gives some basic object services, which may be needed in a distributed application. 1.  Object namin

Information retrieval during multi-agent system, Information Retrieval duri...

Information Retrieval during Multi-Agent System with Data Mining in Cloud Computing Project Description: I have proposed one research model on "Information Retrieval during M

How to integrate your struts application with spring, To integrate your Str...

To integrate your Struts application with Spring, we have two options: ? Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependenc

Design a system program, System Program Project Description: I want s...

System Program Project Description: I want someone who can study my existing program and from there the updates may be done Skills required: Java, Oracle, MySQL, Softwa

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd