Test Series - oops

Test Number 56/78

Q: Which member can never be accessed by inherited classes?
A. Private member function
B. Public member function
C. Protected member function
D. All can be accessed
Solution: The private member functions can never be accessed in the derived classes. The access specifiers is of maximum security that allows only the members of self class to access the private member functions.
Q: Which syntax among the following shows that a member is private in a class?
A. private: functionName(parameters)
B. private(functionName(parameters))
C. private functionName(parameters)
D. private::functionName(parameters)
Solution: The function declaration must contain private keyword follower by the return type and function name. Private keyword is followed by normal function declaration.
Q: How many private member functions are allowed in a class?
A. Only 1
B. Only 7
C. Only 255
D. As many as required
Solution: There are no conditions applied on the number of private member functions that can be declared in a class. Though the system may restrict use of too many functions depending on memory.
Q: Which function among the following can’t be accessed outside the class in java in same package?
A. public void show()
B. void show()
C. protected show()
D. static void show()
Solution: The protected members are available within the class. And are also available in derived classes. But these members are treated as private members for outside the class and inheritance structure. Hence can’t be accessed.
Q: In java, which rule must be followed?
A. Keyword private preceding list of private member’s
B. Keyword private with a colon before list of private member’s
C. Keyword private with arrow before each private member
D. Keyword private preceding each private member
Solution: The private keyword must be mentioned before each private member. Unlike the rule in C++ to specify private once and list all other private member’s, in java all member declarations must be preceded by the keyword private.
Q: Can main() function be made private?
A. Yes, always
B. Yes, if program doesn’t contain any classes
C. No, because main function is user defined
D. No, never
Solution: The reason given in option “No, because main function is user defined” is wrong. The proper reason that the main function should not be private is that it should be accessible in whole program. This makes the program flexible.
Q: If private member functions are to be declared in C++ then _____________
A. private:
B. private
C. private(private member list)
D. private :-
Solution: The private members doesn’t have to have the keyword with each private member. We only have to specify the keyword private followed by single colon and then private member’s are listed.
Q: If a function in java is declared private then it ______________
A. Can’t access the standard output
B. Can access the standard output
C. Can’t access any output stream
D. Can access only the output streams
Solution: The private members can access any standard input or output. There is no restriction on access to any input or output stream. And since standard input can also be used hence only accessing the output stream is not true.
Q: How to access a private member function of a class?
A. Using object of class
B. Using object pointer
C. Using address of member function
D. Using class address
Solution: Even the private member functions can be called outside the class. This is possible if address of the function is known. We can use the address to call the function outside the class.
Q: Private member functions ____________
A. Can’t be called from enclosing class
B. Can be accessed from enclosing class
C. Can be accessed only if nested class is private
D. Can be accessed only if nested class is public
Solution: The nested class members can’t be accessed in the enclosed class even though other members can be accessed. This is to ensure the class members security and not to go against the rules of private members.

You Have Score    /10