Question

What is the difference between overriding a method and overloading a method with respect to method signatures?

What is the difference between overriding a method and overloading a method with respect to method signatures?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Overloading ;- when two or more methods are in a same class having the same name but they have different signature then this concept is known as overloading.Different signature means different type of parameter, different no. of parameter or different return type.

consider an example;-

class M{

static void sum(int a ,int b){

System.out.println(a+b);

}

static void sum(int a ,int b , int c){

System.out.println(a+b+c);

}

public static void main(String[] args) {

sum(1,2);

sum(1,2,3);

}

}

as we can see two method having same name of sum and having no return type but different no. of parameter so it is overloading concept

Overriding :- when a subclass or child class modified the method of parent class then this concept is known as overriding . Both the method having the same name, same return type,same no. and same type of parameter,so overall means same signature.

consider an example

class X{
   
   public void e()
   {
      System.out.println("H");
   }
}
class Y extends X{
   
   public void e(){
      System.out.println("B");
   }
   public static void main( String args[]) {
      Y obj = new Y();
      
      obj.e();
   }
}
Add a comment
Know the answer?
Add Answer to:
What is the difference between overriding a method and overloading a method with respect to method signatures?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT