Test Series - oops

Test Number 58/78

Q: If public members are to be restricted from getting inherited from the subclass of the class containing that function, which alternative is best?
A. Make the function private
B. Use private inheritance
C. Use public inheritance
D. Use protected inheritance
Solution: If private inheritance is used then the class containing the function will be able to use the function with rules of whichever specifier is used. Then the derived class makes those function the private members of itself. This restricts the public members of parent class from further inheritance.
Q: All the public member functions ___________________
A. Can’t access the private members of a class
B. Can’t access the protected members of a class
C. Can access only public members of a class
D. Can access all the member of its class
Solution: The public member function can access any private, protected and public member of its class. Not only public member function, any member function of a class can access each and every other member declared inside the class. Hence are flexible to program.
Q: If a class have a public member function and is called directly in the main function then ___________________________
A. Undeclared function error will be produced
B. Out of memory error is given
C. Program gives warning only
D. Program shut down the computer
Solution: If the function is called directly without using any object then the compiler doesn’t gets to know that the function have to be called from a specific class. And if there are no global or in-scope function with same name then the compiler produces an error stating that the called function is undeclared.
Q: What is an exception?
A. Problem arising during compile time
B. Problem arising during runtime
C. Problem in syntax
D. Problem in IDE
Solution: The problems that might occur during execution of a program are known as exceptions. The exceptions are unexpected sometimes and can be predicted. Also, the exceptions should be always considered for a better program.
Q: An exception may arise when _______________
A. Input is fixed
B. Input is some constant value of program
C. Input given is invalid
D. Input is valid
Solution: The exceptions may arise because the input given by the user might not be of the same type that a program can manage. If the input is invalid the program gets terminated.
Q: Why do we need to handle exceptions?
A. To prevent abnormal termination of program
B. To encourage exception prone program
C. To avoid syntax errors
D. To save memory
Solution: The exceptions should be handled to prevent any abnormal termination of a program. The program should keep running even if it gets interrupted in between. The program should preferable show the error occurred and then retry the process or just continue the program further.
Q: If a file that needs to be opened is not found in the target location then _____________
A. Exception will be produced
B. Exceptions are not produced
C. Exception might get produced because of syntax
D. Exceptions are not produced because of logic
Solution: The exceptions are produced when anything unexpected happened. The program might not be able to find a file in the target location and hence program produces an exceptions. The exception produced, then terminates the program.
Q: What are two exception classes in hierarchy of java exceptions class?
A. Runtime exceptions only
B. Compile time exceptions only
C. Runtime exceptions and other exceptions
D. Other exceptions
Solution: The exceptions class is having two other derived classes which are of runtime exception handler and for other type of exceptions handling. The runtime exception handler is used to handle the exceptions produced during run time and same with case of other exceptions.
Q: Which is the universal exception handler class?
A. Object
B. Math
C. Errors
D. Exceptions
Solution: Any type of exception can be handled by using class Exceptions. An object of this class is created which can manipulate the exception data. The data can be used to display the error or to run the program further based on error produced.
Q: Which are the two blocks that are used to check error and handle the error?
A. Try and catch
B. Trying and catching
C. Do and while
D. TryDo and Check
Solution: Two blocks that are used to check for errors and to handle the errors are try and catch block. The code which might produce some exceptions is placed inside the try block and then the catch block is written to catch the error that is produced. The error message or any other processing can be done in catch block if the error is produced.

You Have Score    /10