Test Series - oops

Test Number 66/78

Q: Which language among the following doesn’t allow pointers?
A. C++
B. Java
C. Pascal
D. C
Solution: The concept of pointers is not supported in Java. The feature is not given in the language but can be used in some ways explicitly. Though this pointer is supported by java too.
Q: Which is correct syntax for declaring pointer to object?
A. className* objectName;
B. className objectName;
C. *className objectName;
D. className objectName();
Solution: The syntax must contain * symbol after the className as the type of object. This declares an object pointer. This can store address of any object of the specified class.
Q: Which operator should be used to access the members of the class using object pointer?
A. Dot operator
B. Colon to the member
C. Scope resolution operator
D. Arrow operator
Solution: The members can be accessed from the object pointer by using arrow operator. The arrow operator can be used only with the pointer of class type. If simple object is declared, it must use dot operator to access the members.
Q: How does compiler decide the intended object to be used, if more than one object are used?
A. Using object name
B. Using an integer pointer
C. Using this pointer
D. Using void pointer
Solution: This pointer denotes the object, in which it is being used. If member function is called with respect to one object then this pointer refers to the same object members. It can be used when members with same name are involved.
Q: If pointer to an object is declared __________
A. It can store any type of address
B. It can store only void addresses
C. It can only store address of integer type
D. It can only store object address of class type specified
Solution: The address of only the specified class type can get their address stored in the object pointer. The addresses doesn’t differ but they do differ for the amount and type of memory required for objects of different classes. Hence same class object pointer should be used.
Q: What is the size of an object pointer?
A. Equal to size of any usual pointer
B. Equal to size of sum of all the members of object
C. Equal to size of maximum sized member of object
D. Equal to size of void
Solution: The size of object pointer is same as that of any usual pointer. This is because only the address have to be stored. There are no values to be stored in the pointer.
Q: A pointer _________________
A. Can point to only one object at a time
B. Can point to more than one objects at a time
C. Can point to only 2 objects at a time
D. Can point to whole class objects at a time
Solution: The object pointer can point to only one object at a time. The pointer will be able to store only one address at a time. Hence only one object can be referred.
Q: Can pointers to object access the private members of the class?
A. Yes, always
B. Yes, only if it is only pointer to object
C. No, because objects can be referenced from another objects too
D. No, never
Solution: The pointers to an object can never access the private members of the class outside the class. The object can indirectly use those private members using member functions which are public in the class.
Q: Is name of an array of objects is also a pointer to object?
A. Yes, always
B. Yes, in few cases
C. No, because it represents more than one object
D. No, never
Solution: The array name represents a pointer to the object. The name alone can represent the starting address of the array. But that also represents an array which is in turn stored in a pointer.
Q:  How can the address stored in the pointer be retrieved?
A. Using * symbol
B. Using $ symbol
C. Using & symbol
D. Using @ symbol
Solution: The & symbol must be used. This should be done such that the object should be preceded by & symbol and then the address should be stored in another variable. This is done to get the address where the object is stored.

You Have Score    /10