
#11 Known is a drop! Method overriding in JAVA -part 1
What is Method Overriding? When a subclass provides a specific implementation for a method that is already defined in its parent class, it is called method overriding. The overridden method in the subclass must have the same name, parameters, and return type as the method in the parent class. Rules for Method Overriding Same Signature: The overriding method must have the exact same name, number of parameters, and type of parameters as the method in the parent class. Inheritance: Overriding requires an "is-a" relationship (inheritance) between the parent and child classes. Access Modifier: The access modifier of the overriding method in the subclass must be the same as, or less restrictive than (e.g., protected to public), the access modifier in the superclass. Return Type: The return type must be the same as the parent's method, or a subtype of the parent's return type (known as a covariant return type). Covariant return type works only with objects (reference types) not with primitive
Continue reading on Dev.to Tutorial
Opens in a new tab




