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;
}
}
//*****************************************
Watch video Java toString method 🎉 online without registration, duration hours minute second in high quality. This video was added by user Bro Code 06 October 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 95,594 once and liked it 4.4 thousand people.