» » what is the difference between method overloading and method overriding?

Method Overloading in java

  • Method overloading is nothing but defining multiple methods with same name with
    different parameters is known as method overloading
  • while compile time itself we know which method going to get executed.
  • Overloading gives better performance compared to overriding. The reason is that the
    binding of overridden methods is being done at runtime.
  • Argument list should be different while doing method overloading.
  • Return type of overloaded methods should be same.
    static binding is used for overloaded methods
Method overloading interview questions java  

  1. package com.instanceofjava;
  2. class A{
  3.  
  4. public void show(int a){
  5. System.out.println("saidesh");
  6. }
  7.  
  8. public void show(int a,int b){
  9. System.out.println("ajay");
  10. }
  11.  
  12. public void show(float a){
  13. System.out.println("vinod");
  14. }
  15. public static void main(String args[]){
  16.  
  17. A a=new A();
  18.  
  19. a.show(10);
  20. a.show(1,2);
  21. a.show(1.2);
  22.  
  23. }
  24. }
Output:

  1. saidesh
  2. ajay
  3. vinod

Method Overriding in java:
  • Method overriding is nothing but defining multiple methods with same name with
    same definition in super class and sub class is known as Method overriding.
    While Run time only now which method is Executed.
  • Overriding gives slower performance compared to overloading.The reason is that the
    binding of overridden methods is being done at run time.
  • Argument list should be same while doing method overriding.
    Polymorphism applies to overriding. 
  • In method overriding the return type of overriding method can be different from overridden
    method.
  • Dynamic binding used for method overriding methods
Top 10 Interview Programs and questions on method overriding in java  


difference between overloading and overriding in java

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu