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, duration hours minute second in high quality that is uploaded to the channel Bro Code 06 October 2020. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 95,594 times and liked it 4.4 thousand visitors.