Test Series - oops

Test Number 4/78

Q: 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
Solution: 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.
Q: How many objects can be declared of a specific class in a single program?
A. 32768
B. 127
C. As many as you want
D. 1
Solution: You can create as many objects of a specific class as you want, provided enough memory is available.
Q: 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
Solution: 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.
Q: 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];
Solution: 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.
Q: The object can’t be __________
A. Passed by reference
B. Passed by value
C. Passed by copy
D. Passed as function
Solution: 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.
Q: 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
Solution: 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.
Q: Functions can’t return objects.
A. True
B. False
C. 1
D. 0
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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;
Solution: 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.

You Have Score    /10