Keyword this in Java is used to reference to the current object. You can use it :
- to call one constructor from another constructor
- to refer to an instance variable
- to call another method inside the class
Every class in Java is descendant of the Object class. That means that your class inherits the instance methods of the Object. Those methods are:
- equals(Object obj)
Overriding a method allows a subclass to change the implementation for this method that is already provided by the super/parent class. To do that you need to use @Override annotation, and implement the method again with the same amount of arguments. There is an example overriding the toString() method. Normally it will return:
Let’s override the method now.