What is difference overloading and overriding?

devquora
devquora

Posted On: Oct 13, 2020

 

Differences between overloading and overriding

OverloadingOverriding
Overloading is performed at compilation time.Overriding is performed at runtime
Overloading is also called static binding.Overriding is also called dynamic binding.
Overloading is done within the class.Overriding occurs in between two classes that have an IS-A (inheritance) relationship.
It is an example of compile-time polymorphism.It is an example of run time polymorphism.

Overloading Example:

class ExampleClass{  
static int sum(int a,int b){return a+b;}  
static int sum(int a,int b,int c){return a+b+c;}  
}  

Overriding Example:

class Animal{  
	void eat(){System.out.println("eating...");}  
}  
class Dog extends Animal{  
	  void eat(){System.out.println("eating bread...");}  
}   

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Java Interview Questions asked in Citibank

    Explain Multi-Threading in Java?

    It is a process in java through which multiple threads can be executed simultaneously. A thread can be explained as a lightweight sub-process, it is the smallest unit of processing. Both multiprocessi...

    Java Interview Questions asked in Citibank

    Explain the internal working of a hash map?

    In Java, A HashMap is a map used to store mappings or links of key-value pairs that works on the hashing principle. It is considered as a data structure that allows us to store objects and retrieve it...