Encapsulation is binding of attributes and behaviors. Hiding the actual implementation and exposing the functionality of any object.
Hiding the complexity. It is a process of defining communication interface for the functionality and hiding rest of the things.
An abstract class is a special kind of class that cannot be instantiated. It normally contains one or more abstract methods or abstract properties. It provides body to a class.
What is Polymorphism? Mean by more than one form. Ability to provide different implementation based on different number/type of parameters.
Tuesday, November 30, 2010
Sunday, November 21, 2010
Why destructor should be virtual?
In the following code if the destructor is not virtual then the destructor of dervied calls is not called and clean up could not be done for Derrived class hence result in memory leaks
Usually the destrcutor of child is called first then parents that order is not followed in the following code if virtual keyword is not used.
#include <iostream.h>
class Base
{
public:
Base(){ cout<<"Constructor: Base"<<endl;}
virtual ~Base(){ cout<<"Destructor : Base"<<endl;}
};
class Derived: public Base
{
//Doing a lot of jobs by extending the functionality
public:
Derived(){ cout<<"Constructor: Derived"<<endl;}
~Derived(){ cout<<"Destructor : Derived"<<endl;}
};
void main()
{
Base *Var = new Derived();
delete Var;
}
Usually the destrcutor of child is called first then parents that order is not followed in the following code if virtual keyword is not used.
#include <iostream.h>
class Base
{
public:
Base(){ cout<<"Constructor: Base"<<endl;}
virtual ~Base(){ cout<<"Destructor : Base"<<endl;}
};
class Derived: public Base
{
//Doing a lot of jobs by extending the functionality
public:
Derived(){ cout<<"Constructor: Derived"<<endl;}
~Derived(){ cout<<"Destructor : Derived"<<endl;}
};
void main()
{
Base *Var = new Derived();
delete Var;
}
Can we have virtual constructor?
No, I think this is syntax error
Constructor is responsible for creating the instance of the class it cannot delegate the responsibility to other class.
Constructor is responsible for creating the instance of the class it cannot delegate the responsibility to other class.
Wednesday, November 10, 2010
Famous - Abstract Class and Concrete Class
Abstract Class which does not provide implementation of all its member functions.
Subscribe to:
Posts (Atom)