Test Series - oops

Test Number 5/78

Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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();
Solution: 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();.
Q: 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] };
Solution: 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.
Q: 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
C. 1
D. 0
Solution: 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.
Q: Which feature of OOP indicates code reusability?
A. Encapsulation
B. Inheritance
C. Abstraction
D. Polymorphism
Solution: Inheritance indicates the code reusability. Encapsulation and abstraction are meant to hide/group data into one element. Polymorphism is to indicate different tasks performed by a single entity.
Q: If a function can perform more than 1 type of tasks, where the function name remains same, which feature of OOP is used here?
A. Encapsulation
B. Inheritance
C. Polymorphism
D. Abstraction
Solution: For the feature given above, the OOP feature used is Polymorphism. Example of polymorphism in real life is a kid, who can be a student, a son, a brother depending on where he is.
Q: If different properties and functions of a real world entity is grouped or embedded into a single element, what is it called in OOP language?
A. Inheritance
B. Polymorphism
C. Abstraction
D. Encapsulation
Solution: It is Encapsulation, which groups different properties and functions of a real world entity into single element. Abstraction, on other hand, is hiding of functional or exact working of codes and showing only the things which are required by the user.
Q: Which of the following is not a feature of pure OOP?
A. Classes must be used
B. Inheritance
C. Data may/may not be declared using object
D. Functions Overloading
Solution: Data must be declared using objects. Object usage is mandatory because it in turn calls its constructors, which in turn must have a class defined. If object is not used, it is a violation of pure OOP concept.
Q: Which among the following doesn’t come under OOP concept?
A. Platform independent
B. Data binding
C. Message passing
D. Data hiding
Solution: Platform independence is not feature of OOP. C++ supports OOP but it’s not a platform independent language. Platform independence depends on programming language.

You Have Score    /10