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

Explain the role of remote interface in rmi, The Remote interface serves to...

The Remote interface serves to recognize interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly ex

Prepare android antivirus with locate device capability, Prepare Android An...

Prepare Android Antivirus with locate device capability Project Description: We need a developer that can develop an Android Antivirus similar to lookout Developer need to prov

Write html and javascript code which displays a textbox, Write HTML and Jav...

Write HTML and JavaScript code which displays a textbox and button on a web page? While user enters text in the text box and clicks the button it displays in that text in the m

Assignment, For this Assignment, submit the following program: Create an ap...

For this Assignment, submit the following program: Create an application for an animal-fur trimming service. The business is open 15 weeks of the year, from April through July. The

Application for android studio, 1- I need application used android studio w...

1- I need application used android studio with source code and all file . same this application : 2-">https://play.google.com/store/apps/details?id=com.magnetic.openmaps&hl=en 2

Extraction of articles, Extraction of articles The software I'm looking ...

Extraction of articles The software I'm looking to build: 1. Extraction of articles from various sites 2. Format the content to re-post 3. Automate the process Skill

What is the role of fonts in java explain with example, What is the role of...

What is the role of fonts in java explain with example? You've already seen one instance of drawing text in the HelloWorldApplet program of the last chapter. You call the drawS

Develop a java application, Project Description: Modules of software: ...

Project Description: Modules of software: 1 - Serial RS232 comm port comunication 2 - NanoHTTPD serving some processed pages 3 - System tray application to indicate sta

Write program to passing arguments to methods, Write program to Passing Arg...

Write program to Passing Arguments to Methods ? It's generally considered bad form to access fields directly. Instead it is considered outstanding object oriented practice to

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