Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Parrot Information Display | Classes
Java Extended
course content

Kursinnehåll

Java Extended

Java Extended

1. Deep Java Structure
2. Methods
3. String Advanced
4. Classes
5. Classes Advanced

book
Challenge: Parrot Information Display

Uppgift

Swipe to start coding

Your task is to write a toString() method that will display all the information about the parrot.

  1. In the toString() method, use the return keyword to specify the output of the method.
  2. Start by creating a string, either using concatenation or string formatting, beginning with something like Parrot{.
  3. Add each field to the string, using + for concatenation, and include both the field name and its value (e.g., "name='" + name + "'").
  4. Separate each field with a comma and a space for better readability.
  5. End the string with a closing brace } to properly represent the object.
  6. Finally, return the formatted string from the toString() method.

Lösning

java

solution

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 9
toggle bottom row

book
Challenge: Parrot Information Display

Uppgift

Swipe to start coding

Your task is to write a toString() method that will display all the information about the parrot.

  1. In the toString() method, use the return keyword to specify the output of the method.
  2. Start by creating a string, either using concatenation or string formatting, beginning with something like Parrot{.
  3. Add each field to the string, using + for concatenation, and include both the field name and its value (e.g., "name='" + name + "'").
  4. Separate each field with a comma and a space for better readability.
  5. End the string with a closing brace } to properly represent the object.
  6. Finally, return the formatted string from the toString() method.

Lösning

java

solution

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 9
Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Vi beklagar att något gick fel. Vad hände?
some-alt