Object Oriented Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Object Oriented Programming MCQ (Multiple Choice Questions)

 Que- Default constructor initializes all data members as: 

a. All numeric member with some garbage values and string to random string 

b. All numeric member with some garbage values and string to null 

c. All numeric member with zero and strings to random value 

d. All numeric member with zero and strings to null 


Ans- All numeric member with zero and strings to null  


Que- When is the static constructor called? 

a. After the first instance is created 

b. Before default constructor call of first instance 

c. Before first instance is created 

d. At time of creation of first instance 


Ans- Before first instance is created  


Que- If constructors of a class are defined in private access, then: 

a. The class can't be inherited 

b. The class can be inherited 

c. Instance can be created only in another class 

d. Instance can be created anywhere in the program 


Ans- The class can't be inherited  


Que- Copy constructor is a constructor which ________________ 

a. Creates an object by copying values from any other object of same class 

b. Creates an object by copying values from first object created for that class 

c. Creates an object by copying values from another object of another class 

d. Creates an object by initializing it with another previously created object of same class 


Ans- Creates an object by initializing it with another previously created object of same class  


Que- The copy constructor can be used to: 

a. Initialize one object from another object of same type 

b. Initialize one object from another object of different type 

c. Initialize more than one object from another object of same type at a time 

d. Initialize all the objects of a class to another object of another class 


Ans- Initialize one object from another object of same type  


Que- If two classes have exactly same data members and member function and only they differ by class name. Can copy constructor be used to initialize one class object with another class object? 

a. Yes, possible 

b. Yes, because the members are same 

c. No, not possible 

d. No, but possible if constructor is also same 


Ans- No, not possible  


Que- The copy constructors can be used to ________ 

a. Copy an object so that it can be passed to a class 

b. Copy an object so that it can be passed to a function 

c. Copy an object so that it can be passed to another primitive type variable 

d. Copy an object for type casting 


Ans- Copy an object so that it can be passed to a function  


Que- Which returning an object, we can use ____________ 

a. Default constructor 

b. Zero argument constructor 

c. Parameterized constructor 

d. Copy constructor 


Ans- Copy constructor  


Que- If programmer doesn't define any copy constructor then _____________ 

a. Compiler provides an implicit copy constructor 

b. Compiler gives an error 

c. The objects can't be assigned with another objects 

d. The program gives run time error if copying is used 


Ans- Compiler provides an implicit copy constructor  


Que- If a class implements some dynamic memory allocations and pointers then _____________ 

a. Copy constructor must be defined 

b. Copy constructor must not be defined 

c. Copy constructor can't be defined 

d. Copy constructor will not be used 


Ans- Copy constructor must be defined  


Que- What is the syntax of copy constructor? 

a. classname (classname &obj){ /*constructor definition*/ } 

b. classname (cont classname obj){ /*constructor definition*/ } 

c. classname (cont classname &obj){ /*constructor definition*/ } 

d. classname (cont &obj){ /*constructor definition*/ } 


Ans- classname (cont classname &obj){ /*constructor definition*/ }  


Que- Object being passed to a copy constructor ___________ 

a. Must be passed by reference 

b. Must be passed by value 

c. Must be passed with integer type 

d. Must not be mentioned in parameter list 


Ans- Must be passed by reference  


Que- Out of memory error is given when the object _____________ to the copy constructor. 

a. Is passed with & symbol 

b. Is passed by reference 

c. Is passed as  

d. Is not passed by reference 


Ans- Is not passed by reference  


Que- Copy constructor will be called whenever the compiler __________ 

a. Generates implicit code 

b. Generates member function calls 

c. Generates temporary object 

d. Generates object operations 


Ans- Generates temporary object  


Que- The deep copy is possible only with the help of __________ 

a. Implicit copy constructor 

b. User defined copy constructor 

c. Parameterized constructor 

d. Default constructor 


Ans- User defined copy constructor  


Que- Can a copy constructor be made private? 

a. Yes, always 

b. Yes, if no other constructor is defined 

c. No, never 

d. No, private members can't be accessed 


Ans- Yes, always  


Que- The arguments to a copy constructor _____________ 

a. Must be const 

b. Must not be cosnt 

c. Must be integer type 

d. Must be static 


Ans- Must be const  


Que- Which among the following best describes constructor overloading? 

a. Defining one constructor in each class of a program 

b. Defining more than one constructor in single class 

c. Defining more than one constructor in single class with different signature 

d. Defining destructor with each constructor 


Ans- Defining more than one constructor in single class with different signature  


Que- Can constructors be overloaded in derived class? 

a. Yes, always 

b. Yes, if derived class has no constructor 

c. No, programmer can't do it 

d. No, never 


Ans- No, never  


Que- Does constructor overloading include different return types for constructors to be overloaded? 

a. Yes, if return types are different, signature becomes different 

b. Yes, because return types can differentiate two functions 

c. No, return type can't differentiate two functions 

d. No, constructors doesn't have any return type 


Ans- No, constructors doesn't have any return type  


Que- Which among the following is possible way to overload constructor? 

a. Define default constructor, 1 parameter constructor and 2 parameter constructor 

b. Define default constructor, zero argument constructor and 1 parameter constructor 

c. Define default constructor, and 2 other parameterized constructors with same signature 

d. Define 2 default constructors 


Ans- Define default constructor, 1 parameter constructor and 2 parameter constructor  


Que- Which among the following is false for a constructor? 

a. Constructors doesn't have a return value 

b. Constructors are always user defined 

c. Constructors are overloaded with different signature 

d. Constructors may or may not have any arguments being accepted 


Ans- Constructors are always user defined  


Que- When is the constructor called for an object? 

a. As soon as overloading is required 

b. As soon as class is derived 

c. As soon as class is created 

d. As soon as object is created 


Ans- As soon as object is created  


Que- Which among the following function can be used to call default constructor implicitly in java? 

a. this() 

b. that() 

c. super() 

d. sub() 


Ans- this()  


Que- Why do we use constructor overloading? 

a. To use different types of constructors 

b. Because it's a feature provided 

c. To initialize the object in different ways 

d. To differentiate one constructor from another 


Ans- To initialize the object in different ways  


Que- If programmer have defined parameterized constructor only, then __________________ 

a. Default constructor will not be created by the compiler implicitly 

b. Default constructor will be created by the compiler implicitly 

c. Default constructor will not be created but called at runtime 

d. Compile time error 


Ans- Default constructor will not be created by the compiler implicitly  


Que- Which among the following is not valid in java? 

a. Constructor overloading 

b. Recursive constructor call 

c. Default value constructors 

d. String argument constructor 


Ans- Recursive constructor call  


Que- What is we only create an object but don't call any constructor for it in java? 

a. Implicit constructor will be called 

b. Object is initialized to some null values 

c. Object is not created 

d. Object is created but points to null 


Ans- Object is created but points to null  


Que- Which among the following is false? 

a. Constructor can't be overloaded in Kotlin 

b. Constructors can't be called recursively in java 

c. Constructors can be overloaded in C++ 

d. Constructors overloading depends on different signatures 


Ans- Constructor can't be overloaded in Kotlin  


Que- Which is correct syntax? 

a. classname objectname= new() integer; 

b. classname objectname= new classname; 

c. classname objectname= new classname(); 

d. classname objectname= new() classname(); 


Ans- classname objectname= new classname();  


Que- Which among the following best describes the constructors? 

a. A function which is called whenever an object is referenced 

b. A function which is called whenever an object is created to initialize the members 

c. A function which is called whenever an object is assigned to copy the values 

d. A function which is called whenever an object is to be given values for members 


Ans- A function which is called whenever an object is created to initialize the members  


Que- Which among the following best describes destructor? 

a. A function which is called just before the objects are destroyed 

b. A function which is called after each reference to the object 

c. A function which is called after termination of the program 

d. A function which is called before calling any member function 


Ans- A function which is called just before the objects are destroyed  


Que- Which among the following represents correct constructor? 

a. ()classname 

b. ~classname() 

c. ||classname() 

d. classname() 


Ans- classname()  


Que- Which among the following is correct syntax for the destructors? 

a. classname() 

b. ()classname 

c. ~classname() 

d. -classname() 


Ans- ~classname()  


Que- Which among the following is true? 

a. First the constructor of parent classes are called in sequence of inheritance 

b. First the constructor of child classes are called in the sequence of inheritance 

c. First constructor called is of the object being created 

d. Constructors are called randomly 


Ans- First the constructor of parent classes are called in sequence of inheritance  


Que- What is the sequence of destructors call? 

a. Same order as that of the constructors call 

b. Random order 

c. According to the priority 

d. Revere of the order of constructor call 


Ans- Revere of the order of constructor call  


Que- The destructors _____________________ 

a. Can have maximum one argument 

b. Can't have any argument 

c. Can have more than one argument 

d. Can't have more than 3 arguments 


Ans- Can't have any argument  


Que- Destructor calls ________________ (C++) 

a. Are only implicit 

b. Are only explicit 

c. Can be implicit or explicit 

d. Are made at end of program only 


Ans- Can be implicit or explicit  


Que- Number of destructors called are 

a. Always equal to number of constructors called 

b. Always less than the number of constructors called 

c. Always greater than the number of constructors called 

d. Always less than or equal to number of constructors 


Ans- Always equal to number of constructors called  


Que- For explicit call _________________ 

a. The destructor must be private 

b. The destructor must be public 

c. The destructor must be protected 

d. The destructor must be defined outside the class 


Ans- The destructor must be public  


Que- Which among the following is true for destructors? 

a. Destructors can be overloaded 

b. Destructors can be define more than one time 

c. Destructors can't be overloaded 

d. Destructors are overloaded in derived classes 


Ans- Destructors can't be overloaded  


Que- The constructor _____________ 

a. Have a return type 

b. May have a return type 

c. Of derived classes have return type 

d. Doesn't have a return type 


Ans- Doesn't have a return type  


Que- The destructors ____________ 

a. Have a return type 

b. May have a return type 

c. Of derived classes have return type 

d. Doesn't have a return type 


Ans- Doesn't have a return type  


Que- Which among the following describes a destructor? 

a. A special function that is called to free the resources, acquired by the object 

b. A special function that is called to delete the class 

c. A special function that is called anytime to delete an object 

d. A special function that is called to delete all the objects of a class 


Ans- A special function that is called to free the resources, acquired by the object  


Que- When a destructor is called? 

a. After the end of object life 

b. Anytime in between object's lifespan 

c. At end of whole program 

d. Just before the end of object life 


Ans- Just before the end of object life  


Que- Which among the following is correct for abstract class destructors? 

a. It doesn't have destructors 

b. It has destructors 

c. It may or may not have destructors 

d. It contains an implicit destructor 


Ans- It doesn't have destructors  


Que- If in multiple inheritance, class C inherits class B, and Class B inherits class A. In which sequence are their destructors called, if an object of class C was declared? 

a. ~C() then ~B() then ~A() 

b. ~B() then ~C() then ~A() 

c. ~A() then ~B() then ~C() 

d. ~C() then ~A() then ~B() 


Ans- ~C() then ~B() then ~A()  


Que- Choose the correct sequence of destructors being called for the following code:class A{ };class B{ };class C: public A, public B{ }; 

a. ~A(), ~B(), ~C() 

b. ~B(), ~C(), ~A() 

c. ~A(), ~C(), ~B() 

d. ~C(), ~B(), ~A() 


Ans- ~C(), ~B(), ~A()  


Que- When is the destructor of a global object called? 

a. Just before end of program 

b. Just after end of program 

c. With the end of program 

d. Anytime when object is not needed 


Ans- Just before end of program  


Que- How the constructors and destructors can be differentiated? 

a. Destructor have a return type but constructor doesn't 

b. Destructors can't be defined by the programmer, but constructors can be defined 

c. Destructors are preceded with a tilde (~) symbol, and constructor doesn't 

d. Destructors are same as constructors in syntax 


Ans- Destructors are preceded with a tilde (~) symbol, and constructor doesn't  


Que- Destructors can be ________ 

a. Abstract type 

b. Virtual 

c. Void 

d. Any type depending on situation 


Ans- Virtual  


Que- Global destructors execute in ___________ order after main function is terminated 

a. Sequential 

b. Random 

c. Reverse 

d. Depending on priority 


Ans- Reverse  


Que- When is it advised to have user defined destructor? 

a. When class contains some pointer to memory allocated in class 

b. When a class contains static variables 

c. When a class contains static functions 

d. When a class is inheriting another class only 


Ans- When class contains some pointer to memory allocated in class  


Que- Which among the following is correct for destructors concept? 

a. Destructors can be overloaded 

b. Destructors can have only one parameter at maximum 

c. Destructors are always called after object goes out of scope 

d. There can be only one destructor in a class 


Ans- There can be only one destructor in a class  


Que- Which class destructor will be called first, when following code go out of scope?class A{  };class B{  };class C: public B{  };A a;B b;C c; 

a. ~A() 

b. ~B() 

c. ~C() 

d. ~B() and ~C() 


Ans- ~C()  


Que- When an object is passed to a function, its copy is made in the function and then: 

a. The destructor of the copy is called when function is returned 

b. The destructor is never called in this case 

c. The destructor is called but it is always implicit 

d. The destructor must be user defined 


Ans- The destructor of the copy is called when function is returned  


Que- What happens when an object is passed by reference? 

a. Destructor is not called 

b. Destructor is called at end of function 

c. Destructor is called when function is out of scope 

d. Destructor is called when called explicitly 


Ans- Destructor is not called  


Que- How many types of access specifiers are provided in OOP (C++)? 

a. 1 

b. 2 

c. 3 

d. 4 


Ans- 3  


Que- Which among the following can be used together in a single class? 

a. Only private 

b. Private and Protected together 

c. Private and Public together 

d. All three together 


Ans- All three together  


Que- Which among the following can restrict class members to get inherited? 

a. Private 

b. Protected 

c. Public 

d. All three 


Ans- Private  


Que- Which access specifier is used when no access specifier is used with a member of class (java)? 

a. Private 

b. Default 

c. Protected 

d. Public 


Ans- Default  


Previous Post Next Post

Responsive Ad