Method Overriding and the final Keyword

Learn about method overriding and when to use the final keyword.

Apart from having its own properties and methods, a child class can override the properties and methods of the parent class.

Overriding properties and methods

When we override a class’s properties and methods, we use the child class to rewrite a method or property that exists in the parent class but assign it a different value or code.

Example

In the example below, we create a hello() method in the parent class that returns the string beep. We override this method in the child class with a method of the same name that returns the string Hallo.

Get hands-on with 1200+ tech skills courses.