31/01/25 ---------- METHOD OVERRIDING ------------------------- Q)What is method overriding? =>Redefining the functionality of super class method in sub class is nothing but method overriding. =>When method overriding is implemented,super class method is known as "overridden" method.Sub class method is known as overriding method. =>When method overriding is implemented, always child class version(overridding method) only will be executed. Q)What are the rules to implement method overriding? 1)both the methods should have same signature. 2)return type should be the same. 3)sub class version of the method should not have weaker access privileges than that of super class method 4)child class method should not have announced more number of checked exceptions than that of the super class method. Q)When to go for method overriding? 1)parent given functionlity is not required for sub class object. 2)parent given functionlity is insufficient. 3)parent has given no functionality but only method name is given Q)Example porgram on method overriding. class Vehicle{ protected void move(){ System.out.println("Every vehicle should move this way"); }//overridden }//super class class Car extends Vehicle{ public void move(){ super.move(); System.out.println("As a car I move my own way also"); }//overriding method }//sub class class OverridingExample { public static void main(String[] args) { Car c=new Car(); c.move(); } }