Remove override Solution – 1

In our last blog, we see the effect of override method, super class’s method become unused. So we have to remove override process from our program. For that we have many solution like create overloading, using super class, dynamic method dispatch and final method. In this blog we will work on override the method.

Remove override : using overloading method

class A

{

                void method()

                {

                                System.out.println(“Welcome in A”);

                }

}

class B extends A

{

                void method(int x)          // overload

                {

                                System.out.println(“Welcome in B”);

                }             

}

class inh5

{

                public static void main(String args[])

                {

                                B b1 = new B();

                                b1.method();     // Call to A Class

                                b1.method(0);  // Call to B Class

                }

}

 

Output:

Welcome in A

Welcome in B

 

About Programs.

In this program, we change parameter of method() function and create overload method. So we have to call both method() and method(int) function from main class and we get both the output.

 

Video available on YouTube.


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe in website


Earn Money Online

1121total visits,7visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image