Overriding is the concept of having functions of same name and signature in different classes. one in the super class can be made virtual and other can override the functionality of virtual one.
Overloading is the concept of having functions of same name, but different signature in same class. They are differentiated by the compiler by their signatures.
Using overloading and overridding, you can acheive the concept of polymorphism.
Polymorphism means "one name, multiple forms". Using one name u can do multiple of actions...
Method overloading is a compile time polymorphism and Method Overridding is a runtime polymorphism...
Compile time polymorphism means compiler knows which object assigned to which class at the compiling time....Runtime polymorphism means compiler didn't know at the compile time, it only knows at a run time...
When overriding, you change the method behavior for a derived class.
e.g Clas A
{
Virtual void hi(int a)
{
}
}
Class B:A
{
public overrid void hi(int a)
{
}
}
Overloading simply involves having a method with the same name within the class.
Example for Over loading
Class A
{
class a()
{
}
class a(int a)
{
}
}
Overloading is the concept of having functions of same name, but different signature in same class. They are differentiated by the compiler by their signatures.
Using overloading and overridding, you can acheive the concept of polymorphism.
Polymorphism means "one name, multiple forms". Using one name u can do multiple of actions...
Method overloading is a compile time polymorphism and Method Overridding is a runtime polymorphism...
Compile time polymorphism means compiler knows which object assigned to which class at the compiling time....Runtime polymorphism means compiler didn't know at the compile time, it only knows at a run time...
When overriding, you change the method behavior for a derived class.
e.g Clas A
{
Virtual void hi(int a)
{
}
}
Class B:A
{
public overrid void hi(int a)
{
}
}
Overloading simply involves having a method with the same name within the class.
Example for Over loading
Class A
{
class a()
{
}
class a(int a)
{
}
}
No comments:
Post a Comment