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

Code Example 1

// file name: Main.java 
  
class Complex {   
    private double re, im; 
  
    public Complex(double re, double im) { 
        this.re = re; 
        this.im = 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.*/
    @Override
    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); 
        System.out.println(c1); 
    } 
}

Learn ReactJs, React Native from akashmittal.com