Question

What is the toString() method used for? Do you need to create one in your classes...

What is the toString() method used for? Do you need to create one in your classes to use it? Why or why not?

Homework Answers

Answer #1
What is the toString() method used for?
toString() method is used to print String version of any object in java. each object contains a method named toString. so, utilities like System.out.println uses toString to print objects.

Do you need to create one in your classes to use it?
No

Why or why not?
because Object class has toString method already defined which prints object's hash.
since every object inherits from Object class, everyone inherits from Object and so, they have toString method.
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(Use JAVA) For this program, you need to create three classes, one of which is a...
(Use JAVA) For this program, you need to create three classes, one of which is a main class that includes aggregation from the other two classes. Each of the classes must include at least two fields, multiple constructors, accessor and mutator methods, and toString. Methods in your main class must include: 1. .equals 2. .copy 3. One that passes an object other than the .copy method 4. One that returns an object 5. toString that calls the toStrings from the...
Java For this assignment you need to create at least 5 classes. 1.Create a vehicle class...
Java For this assignment you need to create at least 5 classes. 1.Create a vehicle class ( super class) 2,3. Create two sub classes ( car, bus , truck train or any) for vehicle class 4 Create a subclass (sportscar or schoolbus or Goodstrain or any) for car or bus You need to use the following atleast for one class. Use a protected variable Add constructor for superclass and subclass Override a method which displays a description about the vehicle...
Why do you need to adjust the second lens of a telescope to create a sharp...
Why do you need to adjust the second lens of a telescope to create a sharp image? What are you actually trying to do?
1) add toString method to BankAccount and SavingsAccount classes 2) Override the withdraw() in SavingsAccount so...
1) add toString method to BankAccount and SavingsAccount classes 2) Override the withdraw() in SavingsAccount so that it will not withdraw more money than is currently in the account. 3) Provide constructors for SavingsAccount 4) Add this feature to SavingsAccount: If you withdraw more than 3 times you are charged $10 fee and the fee is immediately withdrawn from your account.once a fee is deducted you get another 3 free withdrawals. 5) Implement the Comparable Interface for SavingsAccount based on...
What do you think is the best method used in the calculation of depreciation? Why is...
What do you think is the best method used in the calculation of depreciation? Why is that?
Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1-...
Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1- Leaf: that implements turn(), which changes the color of the Leaf object and returns true. If for any reason it is unable to change color, it should return false (you can come up with a reason for failure). The new color can be determined at random. 2- Document: that implements turn(), which changes the page on the document to the next page and returns...
Give one example of how you have used probability in your life. Were you able to...
Give one example of how you have used probability in your life. Were you able to determine the probability based on the classical method, the relative frequency method, or the subjective method? Explain. Think about all the times you do use probability each day and explain which of the three methods you utilize the most throughout the day, and why
You need to create a marketing strategy to advertise an upcoming webinar that will be used...
You need to create a marketing strategy to advertise an upcoming webinar that will be used to debut a new product—an underwater drone with a 4K camera. You are familiar with the marketing “rule of seven,” which states that people need to be exposed to a message seven times before they take action. The budget isn’t large, so you need to be creative. Your customers tend to be tech savvy. How can you get the right customers to see the...
Do you use probability in your profession or real life? You most likely do without consciously...
Do you use probability in your profession or real life? You most likely do without consciously knowing it. Share one example of how you have used probability in your life. Were you able to determine the probability based on the classical method, the relative frequency method, or the subjective method? Explain. Now think about all of the times you do use probability each day and explain which of the three methods you utilize the most throughout the day and why.
Using Java Create a class named Movie that can be used in your video rental business....
Using Java Create a class named Movie that can be used in your video rental business. The Movie class should track the Motion Picture Association of America (MPAA) rating (e.g., Rated G, PG-13, R), ID Number, and movie title with appropriate accessor and mutator methods. Also create an equals() method that overrides Object ’s equals() method, where two movies are equal if their ID number is identical. Next, create three additional classes named Action, Comedy, and Drama that are derived...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT