250+ TOP MCQs on Objects and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Objects”.

1. Which definition best describes an object?
a) Instance of a class
b) Instance of itself
c) Child of a class
d) Overview of a class
Answer: a
Clarification: An object is instance of its class. It can be declared in the same way that a variable is declared, only thing is you have to use class name as the data type.

2. How many objects can be declared of a specific class in a single program?
a) 32768
b) 127
c) 1
d) As many as you want
Answer: d
Clarification: You can create as many objects of a specific class as you want, provided enough memory is available.

3. Which among the following is false?
a) Object must be created before using members of a class
b) Memory for an object is allocated only after its constructor is called
c) Objects can’t be passed by reference
d) Objects size depends on its class data members
Answer: c
Clarification: Objects can be passed by reference. Objects can be passed by value also. If the object of a class is not created, we can’t use members of that class.

4. Which of the following is incorrect?
a) class student{ }s;
b) class student{ }; student s;
c) class student{ }s[];
d) class student{ }; student s[5];
Answer: c
Clarification: The array must be specified with a size. You can’t declare object array, or any other linear array without specifying its size. It’s a mandatory field.

5. The object can’t be __________
a) Passed by reference
b) Passed by value
c) Passed by copy
d) Passed as function
Answer: d
Clarification: Object can’t be passed as function as it is an instance of some class, it’s not a function. Object can be passed by reference, value or copy. There is no term defined as pass as function for objects.

6. What is size of the object of following class (64 bit system)?

class student {  int rollno;  char  name[20];  static int studentno;  };

a) 20
b) 22
c) 24
d) 28
Answer: c
Clarification: The size of any object of student class will be of size 4+20=24, because static members are not really considered as property of a single object. So static variables size will not be added.

7. Functions can’t return objects.
a) True
b) False
Answer: b
Clarification: Functions can always return an object if the return type is same as that of object being returned. Care has to be taken while writing the prototype of the function.

8. How members of an object are accessed?
a) Using dot operator/period symbol
b) Using scope resolution operator
c) Using member names directly
d) Using pointer only
Answer: a
Clarification: Using dot operator after the name of object we can access its members. It is not necessary to use the pointers. We can’t use the names directly because it may be used outside the class.

9. If a local class is defined in a function, which of the following is true for an object of that class?
a) Object is accessible outside the function
b) Object can be declared inside any other function
c) Object can be used to call other class members
d) Object can be used/accessed/declared locally in that function
Answer: d
Clarification: For an object which belongs to a local class, it is mandatory to declare and use the object within the function because the class is accessible locally within the class only.

10. Which among the following is wrong?
a) class student{ }; student s;
b) abstract class student{ }; student s;
c) abstract class student{ }s[50000000];
d) abstract class student{ }; class toppers: public student{ }; topper t;
Answer: b
Clarification: We can never create instance of an abstract class. Abstract classes doesn’t have constructors and hence when an instance is created there is no facility to initialize its members. Option d is correct because topper class is inheriting the base abstract class student, and hence topper class object can be created easily.

11. Object declared in main() function _____________
a) Can be used by any other function
b) Can be used by main() function of any other program
c) Can’t be used by any other function
d) Can be accessed using scope resolution operator
Answer: c
Clarification: The object declared in main() have local scope inside main() function only. It can’t be used outside main() function. Scope resolution operator is used to access globally declared variables/objects.

12. When an object is returned___________
a) A temporary object is created to return the value
b) The same object used in function is used to return the value
c) The Object can be returned without creation of temporary object
d) Object are returned implicitly, we can’t say how it happens inside program
Answer: a
Clarification: A temporary object is created to return the value. It is created because the object used in function is destroyed as soon as the function is returned. The temporary variable returns the value and then gets destroyed.

13. Which among the following is correct?
a) class student{ }s1,s2; s1.student()=s2.student();
b) class student{ }s1; class topper{ }t1; s1=t1;
c) class student{ }s1,s2; s1=s2;
d) class student{ }s1; class topper{ }t1; s1.student()=s2.topper();
Answer: c
Clarification: Only if the objects are of same class then their data can be copied from to another using assignment operator. This actually comes under operator overloading. Class constructors can’t be assigned any explicit value as in option class student{ }s1; class topper{ }t1; s1=t1; and class student{ }s1; class topper{ }t1; s1.student()=s2.topper();.

14. Which among following is correct for initializing the class below?

class student{
int marks;
int cgpa;
public: student(int i, int  j){
marks=I;
cgpa=j
}
};

a) student s[3]={ s(394, 9); s(394, 9); s(394,9); };
b) student s[2]={ s(394,9), s(222,5) };
c) student s[2]={ s1(392,9), s2(222,5) };
d) student s[2]={ s[392,9], s2[222,5] };
Answer: b
Clarification: It is the way we can initialize the data members for an object array using parameterized constructor. We can do this to pass our own intended values to initialize the object array data.

15. Object can’t be used with pointers because they belong to user defined class, and compiler can’t decide the type of data may be used inside the class.
a) True
b) False
Answer: b
Clarification: The explanation given is wrong because object can always be used with pointers like with any other variables. Compiler doesn’t have to know the structure of the class to use a pointer because the pointers only points to a memory address/stores that address.

Leave a Reply

Your email address will not be published. Required fields are marked *