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

Area under the curve, write a program to find the area under the curvey y=f...

write a program to find the area under the curvey y=f(x) between x=a and x=b.integrate y=f(x) between the limits of a and b. the area under a curve between two points can be found

Describe the ? operator in java langauge, Describe The ? operator in Java l...

Describe The ? operator in Java langauge? The conditional operator just works for assigning a value to a variable, using a value within a method invocation, or in a few other w

Develop a computer program and application, Develop a Computer program and ...

Develop a Computer program and application. Project Description: I want a project done. It is a computer desktop application program. It is not very hard. If you need the det

I need a dcs source code and jar, I need a DCS (Source code and JAR) to pro...

I need a DCS (Source code and JAR) to process packets from a cheap chinese GPS TK110, the unit is already communicating with the server but is not parsing. So I need someone with e

Develop android network management cms, Project Description: I am seekin...

Project Description: I am seeking a reliable programmer to do the following task. I want a CMS management system to remotely monitor the Android platform on the network the C

What are the services in rmi, An RMI "service" could well be any Java metho...

An RMI "service" could well be any Java method that can be invoked remotely. The other service is the JRMP RMI naming service which is a lookup service.

Fibonacci, Output first x values in the fibonacci sequence, where x is an a...

Output first x values in the fibonacci sequence, where x is an argument to the program. 0, 1, 1, 2, 3, 5, 8, ... Write the fibonacci creation function separate from the main func

Explain function arguments with the help of an example, Explain function ar...

Explain function arguments with the help of an example? Arguments on a function are comma separated list of data enclosed within braces. It describes interface among the web pa

Programming, Byteland county is very famous for luminous jewels. Luminous j...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

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