Instruction

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Override Method

Inheritance in Kotlin lets you create new classes, or subclasses, that inherit properties and behaviors from existing classes, or superclasses. But subclasses aren’t just copycats! They can add their own unique properties and methods, making them more specialized than their superclasses.

Benefits

Method overriding is a powerful tool that promotes code reusability, flexibility, and polymorphism, leading to well-structured and maintainable code.

Override Constructor Properties

As you already know, overriding is a very powerful tool. You can use it not only for methods but also for overriding properties.

Override Special Methods

Now, it’s time to discuss two methods responsible for ensuring equality between class instances: equals() and hashCode().

equals()

So, why is equals() important?

hashCode()

Hashcode is mostly useful for Hash-Based Collections:

See forum comments
Download course materials from Github
Previous: Introduction Next: Demo