Check out example codes for "java tostring override". It will help you in understanding the concepts better.

Code Example 1

// file name: 
class Complex {   
    private double re, im; 
    public Complex(double re, double im) { = re; = im; 
    /* Returns the string representation of this Complex number. 
       The format of string is "Re + iIm" where Re is real part 
       and Im is imagenary part.*/
    public String toString() { 
        return String.format(re + " + i" + im); 
// Driver class to test the Complex class 
public class Main { 
    public static void main(String[] args) { 
        Complex c1 = new Complex(10, 15); 

Learn ReactJs, React Native from