+1 vote
in JAVA by
What is Method overloading? Why is it used in Java?

1 Answer

0 votes
by

What is Method overloading? Why is it used in Java?

Method overriding is a process in which methods inherited by child classes from parent classes are modified as per requirement by the child class. It’s helpful in hierarchical system design where objects share common properties.

Example: Animal class has properties like fur colour, sound. Now dog and cat class inherit these properties and assign values specific to them to the properties.

class Animal { 

    void sound(){ 

    } 

 class Cat extends Animal{ 

     void sound(){ 

         System.out.println("Meow"); 

     } 

class Dog extends Animal{ 

    void sound(){ 

        System.out.println("Bark"); 

    } 

public class OverRide{ 

    public static void main(String args[]){ 

        Cat c=new Cat(); 

        c.sound(); 

        Dog d=new Dog(); 

        d.sound(); 

    } 

Related questions

0 votes
asked May 6, 2020 in C Sharp by SakshiSharma
0 votes
asked Jun 16, 2019 in JAVA by reins.robin
...