UrbanPro
true

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Method Overloading vs Method Overriding

Md Ajmat
16/01/2018 0 0

1. Method Overloading:

Method overloading means a same method with same name can have different implementations/body

by changing one of the follwing thing:

1) Number of Parameters

2) Order of Parameters

3) Type of Parameter

i. Method overloading can be performed only within class but not in the class in parent-child relations.

ii. Method overloading follows the Compile Time polymorphism means the "Method resolution is done by the comipler at compile time based on the object reference".

iii. Method overloading is also called as static polymorphism or Early binding or compile time polymophism.

class Test

{

           void m1()

            {

                      System.out.println("m1 with no-Parameter");

            }

            

           void m1(int x)

            {

                      System.out.println("m1 with 1-Parameter");

            }

             public static void main(String[] args)

             {

                        Test t=new Test();

                         t.m1();//m1 with no Parameter

                         t.m1(10);//m1 with 1 Parameter

              }

}

 

2. Method Overriding:

i. If a child class is not satisfied with the method implementation/body of Parent class method, in that case child class can re-define the parent class method(can change the implementation/body) without changing the signature.

ii. Re-definfing the parent class method in child class is called as method overriding.

iii. Method Overriding follows Runtime polymorphism means the method resolution is done by the JVM at runtime based on the runtime object.

iv. Method Overriding is also called as Dynamic Polymorphism or Late Binding.

v. Method Overriding can be done only in Parent-Child relation.

vi. Method Overriding is best way to desing the "loose coupling System " in which the degree of dependency between the java components are very less.

 

class Parent 

{

             void m1()

             {

                        System.out.println("m1 Of Parent!!");

             } 

}

class Parent extends Child

{

             void m1()

             {

                        System.out.println("I am Changing the body of Parent method in child class!!");

                        System.out.println("m1 Of Child!!");

             } 

}

class OverrideDemo

{

          public static void main(String[] args)

          {

                    Parent p=new Child();

                    p.m1();

          }

}

Output

---------

I am Changing the body of Parent method in child class!!

m1 Of Child!

0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

Example of DependsOnMethod in TestNG
public class dependsonM { @Test public void login() { System.out.println("login"); } @Test (dependsOnMethods = {"login"}) public void email() { //Intentionally I am failing this testcase Assert.assertTrue(false);...
S

Sarthak C.

0 0
0

Java Advantages
In this video, learn about Java and its advantages. Also, check out the difference between Java and C++, Java development kit, Java Run Time Environment (JRE) with a proper demonstration program for better clarity.

Tips of learning Java Language/Other Programming Languages
1.You should know the basic concept: If we talk about programming languages so basic concept are same in all the high level languages. So you should know the basic concept firstly then you can easily understand...
I

ICreative Solution

0 0
0

Android : Application Launch time improvements.
For any standard android application, below 3 components play important roles to show 1st interface to user, so that he/she can interact with the app. 1. Custom Application class : Intialize the components...

Core Java
Introduction: An Object Oriented Programming Language consists of Objects. There are object oriented programming languages like Smalltalk, C++. Each and every OOP language has some underlying disadvantages....
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more