In Java, when a subclass contains a method that overrides a method of the superclass. Example: class A { public void message() { System.out.println("Hi"); } }
public class B extends A { @Override public void message() { System.out.println("Hello"); } } Class A represents the superclass and implements a method call message(). The subclass called B inherits every method that could be in the A class. However, class B overrides the method message(), replacing its functionality from A.
A parking = new A(); parking.message(); // Prints "Hi"
A dates = new B(); // Polymorphism dates.message(); // Prints "Hello"
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment