Monday, January 24, 2011

Constructor Overloading

     Constructor overloading is
a method with one name and perform
variety of task.
  

Constructor

    Constructor is a method which create and intialize objects.
They dont return values,constructor can be default constructor.
It just initialize members and object.Constructor is of same name
as of 'Class'.

Class employee
{
    private:
      int age;
      char name;
  
   public:
     age 1();
     name 1();
}

 employee : age 1()
{
    cout<<"enter age";
    cin>>age;
}

main()
{
   employee e= new employee();
   e.age 1();
   cout<<"age";
}

where 'e' is the object and 'new' for memory allocation,
we declare object and access everything through it.Default
constructor to called class employee.

Pointer & Reference in C++

    Pointer hold an address and use that address to modify
the original value.To access a variable through a pointer we
derefer it.
    Pointer is an Alias for another variable.So if we
pass a pointer into a function,we are actually passing 
an alias to the outside object.

{
    int a=2;
    int &b=a;
    b=24;
    cout<<a>>endl;
}

output will be 24 as b refer to a.

Lvalue & Rvalue

   Variables names are said to be "lvalue"  for left values because
they can be used on the left side of  an assignment operator.
   Constants are said to be "rvalue" for right values because they
can be used on the right side of an assignment operator.

Virtual functions & Overriding

 If a function is declared as virtual in the base class,it is
virtual in all derived classess.
     The redefiniton of virtual function in a derived class
is usually called overriding.
    If we dont want to override the method we can use 'new'.
Marking the method with 'new' tells the compiler that we are not
overriding the base class implementation of method.

Which Programming language you prefer?