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
Answer: Option A
Explanation:
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.
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)
Answer: Option C
Explanation:
The function declaration must contain a private keyword follower by the return type and function name. The private keyword is followed by a normal function declaration.
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()
Answer: Option C
Explanation:
The protected members are available within the class. And are also available in derived classes. But these members are treated as private members outside the class and inheritance structure. Hence can’t be accessed.
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()
Answer: Option C
Explanation:
The protected members are available within the class. And are also available in derived classes. But these members are treated as private members outside the class and inheritance structure. Hence can’t be accessed.
Which error will be produced if private members are accessed?
A.
Can’t access private message
B.
Code unreachable
C.
Core dumped
D.
Bad code
Answer: Option A
Explanation:
The private member's access from outside the class produces an error. The error states that the code at some line can’t access the private members. And denies the access terminating the program.