As it pertains to inheritance differentiate between the conc
As it pertains to inheritance, differentiate between the concept of method overloading and method overriding. Give ONE example of each. (NB: Example alone counts for 0).
Solution
The difference between the concept of method overloading and method overriding :-
Example :-
class Example
{
void m1() {
System.out.println(\"Hi\");
}
class Sample extends Example
{
void m1()
{
System.out.println(\"Hello\");
}
public static void main(String[] args)
{
Sample s = new Sample();
s.m1();
}
}
Example :-
class Example
{
void m1()
 {
System.out.println(\"No-arg add\");
}
   
 void m1(int a)
 {
System.out.println(\"int-arg add\");
}
void m1(String str)
 {
System.out.println(\"String-arg add\");
}
 
 public static void main(String[] args)
{
Example e = new Example();
e.m1();
 e.m1(5);
 e.m1(\"abc\");
}
}
| method Overriding | method Overloading | 
| Providing new implementation to super class method in subclass is called method Overriding | creating new method with same name with different parameters is called method Overloading | 
| We can overide only in sub class | we can overload in same class or in sub class | 
| We can\'t override final method | we can overload final method | 
| Example :- class Example { void m1() { System.out.println(\"Hi\"); } class Sample extends Example { void m1() { System.out.println(\"Hello\"); } public static void main(String[] args) { Sample s = new Sample(); s.m1(); } } | Example :- class Example { void m1() System.out.println(\"No-arg add\"); } System.out.println(\"int-arg add\"); } void m1(String str) System.out.println(\"String-arg add\"); } { Example e = new Example(); e.m1(); } } | 



