GET 100% MARKS IN
COMPUTER SCIENCE
CONSTRUCTOR
AND DESTRUCTOR
IN THIS PART 3 TYPE OF QUESTIONS CAN BE
FORMED IN YOUR EXAM
1. Theory Question (Basically definition or difference or similarities).
2. To identify the type of function (constructor, destructor, copy constructor
etc.)
3. To write calling statement for a particular function.
IMPORTANT THEORY QUESTIONS
Q.1Define Constructor ?when it will be invoked and work/purpose
of constructor ?
Ans. A constructor is a member function with same name as of
class. Which is invoked automatically when an object comes in
scope. And its work/Purpose is to allocate space to object and to
initialize the data members with legal initial values.
IMPORTANT THEORY QUESTIONS
Q.2 Define Destructor ?when it will be invoked and work/purpose
of constructor ?
Ans. A Destructor is a member function with same name as of
class but precedes with a tilde(~) Symbol. Which is invoked
automatically when an object goes out of scope. And its
work/Purpose is to de allocate space & resources allocated during
construction process.
Q.3 DIFFERENCE BETWEEN CONSTRUCTOR & DESTRUCTOR?
CONSTRUCTOR
• It is declared with same name as of
class.
• Works to allocated space and
resources to objects.
• Called automatically when an object
comes in scope.
• Can be overloaded.
• Can contain arguments.
DESTRUCTOR
• Declared with same name as of class but
precedes with a tilde(~ symbol)
• Works to deallocate space and resources
allocated during constuction.
• Called automatically when an object goes
out of scope.
• Can’t be overloaded.
• Can’t contain arguments.
IMPORTANT THEORY QUESTIONS
Q.4 SIMILARITIES BETWEEN CONSTRUCTOR & DESTRUCTOR?
• Both are declared with same name as of class
• Both will be called automatically by compiler.
• Doesn’t contain any return type.
• If we don’t declare a constructor or destructor for a class compiler will by
default provide one to the class.
IMPORTANT THEORY QUESTIONS
Q.5 DEFINE COPY CONSTRUCTOR? WHEN IT WILL BE INVOKED?
Q.6 DEFINE DEFAULT CONSTRUCTOR?
Q.7 DEFINE PARAMETERIZED CONSTRUCTOR?
Q.8 DIFFERENCE BETWEEN EXPLICIT & IMPLICIT
CONSTRUCTOR CALLS?
IMPORTANT THEORY QUESTIONS
TO IDENTIFY THE TYPE OF FUNCTION
Constructor
Class X()
{
X();
X(int a, int b);
};
Destructor
Class X()
{
~X();
};
Copy Constructor
Class X()
{
X(X &obj);
};
TO IDENTIFY & WRITE CALLING STATEMENT FOR A
PARTICULAR FUNCTION
Class XYZ
{
XYZ(); //FUNCTION1
XYZ(int a,int b); //FUNCTION 2
XYZ(XYZ & obj); //function 3
Void show(); //function 4
~XYZ(); //Function 5
};
ANS.
FUCNTION 1 is a default Constructor
XYZ obj;
FUNCTION 2 is an argumented constructor
XYZ obj2(10,20);
FUNCTION 3 is a copy constructor
XYZ obj3=obj2;
Or
XYZ obj4(obj1);
FUNCTION 4 is a member function
Obj4.show();
FUNCTION 5 is a destructor will be called automatically
when an object goes out of scope
Q. Which oops concept is represented by
function1,function 2 and function 3 together
Ans. Constructor overloading or polymorphism
EXAMPLE
THANKS FOR WATCHING MY VIDEO
EMAIL : theaakashkumar@gmail.com

Constructor & destructor based question- cbse cs class 12th

  • 2.
    GET 100% MARKSIN COMPUTER SCIENCE CONSTRUCTOR AND DESTRUCTOR
  • 3.
    IN THIS PART3 TYPE OF QUESTIONS CAN BE FORMED IN YOUR EXAM 1. Theory Question (Basically definition or difference or similarities). 2. To identify the type of function (constructor, destructor, copy constructor etc.) 3. To write calling statement for a particular function.
  • 4.
    IMPORTANT THEORY QUESTIONS Q.1DefineConstructor ?when it will be invoked and work/purpose of constructor ? Ans. A constructor is a member function with same name as of class. Which is invoked automatically when an object comes in scope. And its work/Purpose is to allocate space to object and to initialize the data members with legal initial values.
  • 5.
    IMPORTANT THEORY QUESTIONS Q.2Define Destructor ?when it will be invoked and work/purpose of constructor ? Ans. A Destructor is a member function with same name as of class but precedes with a tilde(~) Symbol. Which is invoked automatically when an object goes out of scope. And its work/Purpose is to de allocate space & resources allocated during construction process.
  • 6.
    Q.3 DIFFERENCE BETWEENCONSTRUCTOR & DESTRUCTOR? CONSTRUCTOR • It is declared with same name as of class. • Works to allocated space and resources to objects. • Called automatically when an object comes in scope. • Can be overloaded. • Can contain arguments. DESTRUCTOR • Declared with same name as of class but precedes with a tilde(~ symbol) • Works to deallocate space and resources allocated during constuction. • Called automatically when an object goes out of scope. • Can’t be overloaded. • Can’t contain arguments. IMPORTANT THEORY QUESTIONS
  • 7.
    Q.4 SIMILARITIES BETWEENCONSTRUCTOR & DESTRUCTOR? • Both are declared with same name as of class • Both will be called automatically by compiler. • Doesn’t contain any return type. • If we don’t declare a constructor or destructor for a class compiler will by default provide one to the class. IMPORTANT THEORY QUESTIONS
  • 8.
    Q.5 DEFINE COPYCONSTRUCTOR? WHEN IT WILL BE INVOKED? Q.6 DEFINE DEFAULT CONSTRUCTOR? Q.7 DEFINE PARAMETERIZED CONSTRUCTOR? Q.8 DIFFERENCE BETWEEN EXPLICIT & IMPLICIT CONSTRUCTOR CALLS? IMPORTANT THEORY QUESTIONS
  • 9.
    TO IDENTIFY THETYPE OF FUNCTION Constructor Class X() { X(); X(int a, int b); }; Destructor Class X() { ~X(); }; Copy Constructor Class X() { X(X &obj); };
  • 10.
    TO IDENTIFY &WRITE CALLING STATEMENT FOR A PARTICULAR FUNCTION Class XYZ { XYZ(); //FUNCTION1 XYZ(int a,int b); //FUNCTION 2 XYZ(XYZ & obj); //function 3 Void show(); //function 4 ~XYZ(); //Function 5 }; ANS. FUCNTION 1 is a default Constructor XYZ obj; FUNCTION 2 is an argumented constructor XYZ obj2(10,20); FUNCTION 3 is a copy constructor XYZ obj3=obj2; Or XYZ obj4(obj1); FUNCTION 4 is a member function Obj4.show(); FUNCTION 5 is a destructor will be called automatically when an object goes out of scope Q. Which oops concept is represented by function1,function 2 and function 3 together Ans. Constructor overloading or polymorphism EXAMPLE
  • 11.
    THANKS FOR WATCHINGMY VIDEO EMAIL : theaakashkumar@gmail.com