This is the blog which we created for the people who have passion on programming.Anyone can visit this group and post their comments,opinions,questions regarding programming.We will get back to you soon with the solution if we have.Please feel free to post.
"Let all be a part of this blog..."
Monday, 19 October 2015
Need explanation.....?
I want to know details regarding polymorphism in sense of method overriding.
Polymorphism means having multiple forms of one thing. In inheritance, polymorphism is done, by method overriding, when both super and sub class have member function with same declaration but different definition.
If we inherit a class into the derived class and provide a definition for one of the base class's function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding.
Inheritance should be there. Function overriding cannot be done within a class. For this we require a derived class and a base class. Function that is redefined must have exactly the same declaration in both base and derived class, that means same name, same return type and same parameter list.
As I understood,It is mainly used in inheritance concept to override the base function in the derived class by using keyword virtual in the base function.
Polymorphism Polymorphism means having multiple forms of one thing. In inheritance, polymorphism is done, by method overriding, when both super and sub class have member function with same declaration bu different definition.
Function Overriding
If we inherit a class into the derived class and provide a definition for one of the base class's function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding
Requirements for Overriding
Inheritance should be there. Function overriding cannot be done within a class. For this we require a derived class and a base class. Function that is redefined must have exactly the same declaration in both base and derived class, that means same name, same return type and same parameter list. Example of Function Overriding
class Base { public: void show() { cout << "Base class"; } }; class Derived:public Base { public: void show() { cout << "Derived Class"; } }
This comment has been removed by the author.
ReplyDeletePolymorphism means having multiple forms of one thing. In inheritance, polymorphism is done, by method overriding, when both super and sub class have member function with same declaration but different definition.
DeleteIf we inherit a class into the derived class and provide a definition for one of the base class's function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding.
Inheritance should be there. Function overriding cannot be done within a class. For this we require a derived class and a base class.
Function that is redefined must have exactly the same declaration in both base and derived class, that means same name, same return type and same parameter list.
As I understood,It is mainly used in inheritance concept to override the base function in the derived class
ReplyDeleteby using keyword virtual in the base function.
Polymorphism
ReplyDeletePolymorphism means having multiple forms of one thing. In inheritance, polymorphism is done, by method overriding, when both super and sub class have member function with same declaration bu different definition.
Function Overriding
If we inherit a class into the derived class and provide a definition for one of the base class's function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding
Requirements for Overriding
Inheritance should be there. Function overriding cannot be done within a class. For this we require a derived class and a base class.
Function that is redefined must have exactly the same declaration in both base and derived class, that means same name, same return type and same parameter list.
Example of Function Overriding
class Base
{
public:
void show()
{
cout << "Base class";
}
};
class Derived:public Base
{
public:
void show()
{
cout << "Derived Class";
}
}
thanks for your replies.
ReplyDelete