Category: 7. OOP(Advanced)
-
Overridden Methods of the superclass
If methods with the same name are defined in both superclass and subclass, the method in the subclass overrides the method in the superclass. This is called method overriding. Example 1: Method overriding Output In this example, by making an object dog1 of Dog class, we can call its method printMessage() which then executes the display() statement. Since display() is defined in both the classes, the…
-
Print object of a class
Java program to print the object Output In the above example, we have created an object of the class Test. When we print the object, we can see that the output looks different. This is because while printing the object, the toString() method of the object class is called. It formats the object in the default format. That…