What is the toString() method used for? Do you need to create one in your classes to use it? Why or why not?
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.
Get Answers For Free
Most questions answered within 1 hours.