I can\'t seem to understand why when I use println method on the quarter object, it returns the value of the toString method. I never called the toString method why am I g
Because all classes in java are subclasses of java.lang.Object , so whenever you try to call System.out.println() method to print object, it calls the toString() method of Object class.
For Security Reasons the method prints a hashcode, not the values of that object, but you have inherited that method in your class and extended its definition to print object values
public String toString() {
return "A Quarter is "+getValue();
}
So you get a return value.