Overriding toString method in Java

If we call toString method on any object in java and print the results to the console it will print somethinf weird which is not very helpful.

If we want toString to print something meaningfull we can override that method in our class like below. Here we have overident he toString method to print the firstName,lastName and age where firstName,lastName and age are three class variables for the concerned object

 @Override
    public String toString() {
        return  " First Name :  " + this.firstName +", Last Name :  " + this.lastName + ", Age :  " +this.age;
    }