Skip to main content

12th HSC free notes of c++ language theory part 4

 What is a constructor ? Why it is called so?

“A constructor is a special member function of a class . Its task is to initialize the objects of its class. ”
It is special because its name is same as that of the class to which it belongs.
The constructor is invoked whenever an object of its associated class is created.
It is called constructor because it constructs the values of data members of the class.
A constructor can never return any value. Hence ,it is written with no return type ( even void is not written ).

Whenever a class contain a constructor like one above , it will be initialized automatically , whenever an object of the class is created.
i.e. the declaration – integer int1;
This not only creates the object int1 of type integer , also initializes its data members m and n to zero .

Give the characteristics of a constructor function .or Syntax rule for writing constructors.
The constructor name is always same as the class name .
They do not have return types , not even void and therefore, they cannot return values.
They cannot be static or virtual .
They should be declared in public section .
They cannot be inherited though a derived class can call base class constructor .
 Like other c++ function , they can have default arguments .
 We cannot refer to their address .
 An object with a constructor cannot be used as a member of union .
 They make implicit calls to the operator ‘new’ and ‘delete’ when memory allocation is required.
 When a constructor is declared for a class , initialization of class objects become mandatory , since constructor is invoked automatically when the objects are created.

What is inheritance ? Explain with suitable example .
 The mechanism of deriving a new class from an old called is inheritance .
 The old class is referred as base class and new class is reffered as derived class.
 C++ strongly supports the concept of reusability . Once a class has been written and tested , if can be adapted by other programmers to suit their requirement .
 This is basically done by creating new classes , reusing the properties of the existing ones
Functions and variables of a class that has been tested can be used by object of another class . This is known as inheritance
. The reuse of a class that has alreadynbeen tested , debugged and used many times , can save the efforts of developing and testing the same again .
Explain the concept of virtual function .
When user use the same function name in both the base and derived classes, the function in the base class is derived as virtual using the keyboard ‘virtual’ preceding its normal declaration .
When a function is made virtual , c++ determines which function to use at runtime , based on the type of object pointed to by the base pointer .
Thus , by making the base pointer to point two different objects it can execute different versions of the virtual function .
Virtual function can be accessed through the use of pointer declared as a pointer to the base class .
Also, the prototypes of the base class version of virtual function and all the derived class version must be identical .
If two functions with the same name have different prototype ,c++ considers them as overload functions , and the virtual mechanism is ingnore


keep study with us.

Comments

Post a Comment

Popular posts from this blog

Free notes of Biomolecules short revision part 1

Biomolecules Polysaccharide are not sweet in taste.               All monosaccharides are reducing sugar.         Monosaccharides are starting from carbon number 3.                                                                Starch contain amylose and amylopectin amylose contain bonding between c1 -c4 and amylopectin has c1-c6 bonding in their structure.                                                                 Monomers: a)Lactose : 1) beta -D galactose 2)beta - D glucose.                                   ...

Free notes of surface tension

  Surface tension.         Intermolecular forces:- The forces of attraction and repulsion between their molecules . These forces ,are called intermolecular . Their is to forces 1) cohesive force.  2) adhesive force. Cohesive force:- the force of attraction between 2 molecules of same substance called as cohesion. Adhesive force:- the force of attraction and repulsion between the two different substance like liquid and solid ,solid with gas etc. is called adhesion. Range of molecular forces:- The maximum distance between 2 molecules upto which intermolecular forces are effective (also called as short range forces). Distance (10 to the power -9). Sphere of influence :- an imaginary sphere drawn with given molecule as centre and radius equal to the molecular range . Surface film :- The layer of surface of liquid whose thickness is about equal to range of molecular attraction. Surface energy :- when a molecular is taken from the inside to the surface layer work...

Free notes of Biomolecules short revision part 2

  Biomolecules part 2. DNA has bases like adenine , gunine , cytosine , thymine.                                                  RNA has bases like adenine, gunine , cytosine , urasil.                                                        Adenine have hydrogen bond with thymine and cytosine have hydrogen bond with gunine.                                                                       D- fructose , D - manose ,D- glucose , form a same osazone product .                        ...