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 all naming reactions .(handwritten notes jee, neet, mht-cet)

All naming reactions  (Handwritten notes.)                   organic chemistry naming reactions.

partitioning (operatimg system ).

 WHAT IS PARTITIONING ? Certain operating system use partitioned memory management to allow multiprogramming . • Partitioning means dividing main memory into various sections.  • These section are called as partitions.  • There are two types of partitions: 1) fixed partition .    2) variable partition.   Fixed partition  .  • In this method partitions are fixed at the time of system generation . At this time , system manager has to declear partition time.  • Fixed partition are also called static partition . On declearing fixed partition , the operating system create partition description table.  • It reduces the uses the CPU utiliisation .  • It reduces the degree of multiprogramming. .    variable partition .     In variable partition number of partition and their size are variable  • They are not defined at the time of system generation .  • These partition are created by operating systems...

Question bank of operating system CS.

  Question Bank Standard:- 12th Subject:- Computer Science (D9) Paper I March 2021 सूचना 1. फक्त शवद्यार्थ्यांना प्रश्नप्रकारांचा सराव करून देण्यासाठीच 2. सदर प्रश्नसंचातील प्रश्न बोर्डाच्या प्रश्नपशिके त येतीलच असे नाही याची नोंद घ्यावी. QUESTION BANK XII COMPUTER SCIENCE (D9) – PAPER I CHAPTER 1 – OPERATING SYSTEM MCQ – 1 Mark Q.No. Question Marking scheme 1. Operating system is a __________ i) hardware ii ) software iii) printer iv) input device 1 mark for correct alternative 2. ‘Open files’ is a system call provided under _________ of operating system. i) Information management ii) Process management iii) Memory management iv) GUI 1 mark for correct alternative 3. Program under execution is known as __________. i) File ii) Information iii) Data iv ) Process 1 mark for correct alternative 4. _______is a service of memory management of operating system. i) Copy a file ii) Suspend a Process iii) Allocate a chunk of memory iv) Open a directory 1 mark for correct alternative...