Object class has following five non final methods.
1. clone()
2. equals(Object obj)
3. finalize()
4. hashCode()
5. toString()
Every Java class has Object as a super class so by default all above methods are provided in every java class. In this article we will discuss in detail the concepts of toString() method. We will discuss why it is necessary to override toString method and how we can override it.
The toString() method in the Object class is used to display some information regarding any object.The toString method is widely implemented. It provides a simple, convenient mechanism for debugging classes during development.When debugging, you want to be able to print a human readable representation of your object.It is widely used for logging.
The toString() method of an object gets invoked automatically, when an object reference is passed in the System.out.println() method.
1. clone()
2. equals(Object obj)
3. finalize()
4. hashCode()
5. toString()
Every Java class has Object as a super class so by default all above methods are provided in every java class. In this article we will discuss in detail the concepts of toString() method. We will discuss why it is necessary to override toString method and how we can override it.
The toString() method in the Object class is used to display some information regarding any object.The toString method is widely implemented. It provides a simple, convenient mechanism for debugging classes during development.When debugging, you want to be able to print a human readable representation of your object.It is widely used for logging.
The toString() method of an object gets invoked automatically, when an object reference is passed in the System.out.println() method.