This Set of Object Oriented Programming Objects Four
This Set of Object Oriented Programming Objects Four
a) 20
b) 22
c) 24
d) 28
View Answer
Answer: c
Explanation: 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
View Answer
Answer: b
Explanation: 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
View Answer
Answer: a
Explanation: 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
View Answer
Answer: d
Explanation: 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;
View Answer
Answer: b
Explanation: 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
View Answer
Answer: c
Explanation: 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
View Answer
Answer: a
Explanation: 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();
View Answer
Answer: c
Explanation: 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
}
};