Java toString method 🎉

Published: 06 October 2020
on channel: Bro Code
95,594
4.4k

Java toString method tutorial explained

#Java #toString #method #tutorial #explained

//*****************************************
public class Main {

public static void main(String[] args) {

// toString() = special method that all objects inherit,
// that returns a string that "textually represents" an object.
// can be used both implicitly and explicitly

Car car = new Car();


System.out.println(car.toString());

// or

System.out.println(car);


}
}
//*****************************************
public class Car {


String make = "Ford";
String model = "Mustang";
String color = "red";
int year = 2021;

public String toString() {

return make +"\n"+model+"\n"+color+"\n"+year;

}
}
//*****************************************


On this page of the site you can watch the video online Java toString method 🎉 with a duration of hours minute second in good quality, which was uploaded by the user Bro Code 06 October 2020, share the link with friends and acquaintances, this video has already been watched 95,594 times on youtube and it was liked by 4.4 thousand viewers. Enjoy your viewing!