RE: What is the difference between OVERRIDING and OVER...
Overloading is compile time binding where as overriding is dynamic binding.A good example that differentiates between overloading and overriding is shown here.
RE: What is the difference between OVERRIDING and OVER...
Please clarify the difference class A { void calc() { } int calc(int) { } } class B:public A { void calc() { } }
This is just an abstract of the program. If we have a program like this and an object of class B is created and we call b.calc will the compiler first call the method calc of super class or sub class? What will be the effect of virtual key word on this program? Is the calc function over loaded? Can we say this as an example for over riding?
RE: What is the difference between OVERRIDING and OVER...
Please clarify the difference class A { void calc() { } int calc(int) { } } class B:public A { void calc() { } }
This is just an abstract of the program. If we have a program like this and an object of class B is created and we call b.calc will the compiler first call the method calc of super class or sub class? What will be the effect of virtual key word on this program? Is the calc function over loaded? Can we say this as an example for over riding?
------------------------------------------------------------------------- In this case when class B calls a.calc the complier will first look at the signature of calc. Class B needs to either call a.calc() or a.calc(int).
RE: What is the difference between OVERRIDING and OVERLOADING
Overloading: Methods name same but signatures is different in the class.
Example:
class b{
public void add(int i int j){ int n i+j; System.out.println(n); } public void add(int i int j int k){ int n i+j+k; System.out.println(n); } public void add(int i int j int k int l){ int n i+j+k+l; System.out.println(n); } public static void main(String []aa){ b b1 new b(); b1.add(1 2 5); } } output: 8
Overriding:To redefine the base class method in the derived class is called overriding.
Example:
class a{
public void display(){ System.out.println( it is a firest class method ); } } class overiding extends a{
public void display(){ System.out.println( it is a Second class method ); } public static void main(String []anil){ overiding obj new overiding();
RE: What is the difference between OVERRIDING and OVERLOADING
OvERLOADING: Same function with different arguments ADDITION(int x int y) ADDITION(int x int y int z) { { ------------------------- --------------- -------------------------- ------------------- } } OVERRIDING: Same function with same arguments
ADDITION(int x int y) ADDITION(float x float y) { { ------------------------- --------------- -------------------------- ------------------- } }