Test Series - oops

Test Number 57/78

Q: What are public member functions?
A. Functions accessible outside the class but not in derived class
B. Functions accessible outside the class directly
C. Functions accessible everywhere using object of class
D. Functions that can’t be accessed outside the class
Solution: The most suitable definition would be that public member functions are accessible everywhere using object of the class. If derived classes are using those, derived class object can be used to call those functions.
Q: Which public function call among the following is correct outside the class, if return type is void (C++)?
A. object.void functionName(parameters);
B. object.functionName(parameters);
C. object.functionName void (parameters)
D. object.void functionName();
Solution: The condition given says that there is no return type hence we can call the function directly. The object name should be mentioned with a dot operator to access its class members. Then the function name with parameters, if required, can be given.
Q: How many public members are allowed in a class?
A. Only 1
B. At most 7
C. Exactly 3
D. As many as required
Solution: The number of public members that can be defined in a class doesn’t have any limit. Though the programmer should not use too many functions, instead should use another class for more specific functions to reduce the readability complexity.
Q: Which call is correct for public members of a nested class?
A. Can be called from object of enclosing class
B. Can be called within enclosing class only with direct names
C. Direct names should be used for the nested classes
D. Only with help of nested class object pointer
Solution: The closest definition is that any public member function of the nested class can be accessed with the help of enclosing class object. The nested class object pointer can be used only within the enclosing class. It’s not mandatory to use the members of nested class only within the enclosing class.
Q: Which is not a proper way to access public members of a class?
A. Using object pointer with arrow operator
B. Using object of class in main function
C. Using object of class with arrow operator
D. Using object anywhere in the program
Solution: The public members can be accessed anywhere in the program using the object of the class. And if object pointer is used, then arrow operator is used to access class members. If normal object is used with arrow operator, an error will be generated.
Q: Which syntax among the following is correct for public member functions?
A. public::void functionName(parameters)
B. public void functionName(parameters)
C. public(void functionName(parameters))
D. public:-void functionName(Parameters)
Solution: The public member functions declaration must be mentioned with the keyword public. The syntax given is used in java. Keyword public is followed by the usual function declaration.
Q: Which among the following is true for public member functions?
A. Public member functions doesn’t have a return type
B. Public member functions doesn’t have any security
C. Public member functions are declared outside the class
D. Public member functions can be called using object of class
Solution: The public member functions can be called using object of the class. The members can’t be declared outside the class as those would become non-member functions of the class. The functions have security as those can be accessed using the class object only.

You Have Score    /7