Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

If static data member are made inline, ______________(a) Those should be initialized outside the class(b) Those can’t be initialized with the class(c) Those can be initialized within the class(d) Those can’t be used by class membersThe question was asked in unit test.Question is taken from Static Member Functions topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right choice is (C) Those can be initialized WITHIN the class

Explanation: SINCE the members are created once and are common for all the instances, those can be initialized inside the class. Those doesn’t CHANGE with each object being created hence can be defined inside the class once for all.

2.

The static data member _________________(a) Can be mutable(b) Can’t be mutable(c) Can’t be integer(d) Can’t be charactersThe question was asked at a job interview.This intriguing question originated from Static Member Functions in section Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct ANSWER is (b) Can’t be mutable

To explain I would SAY: The static data members can NEVER be mutable. There copies are not made. Since those are COMMON and created only once.

3.

We can use the static member functions and static data member __________________(a) Even if class object is not created(b) Even if class is not defined(c) Even if class doesn’t contain any static member(d) Even if class doesn’t have complete definitionThis question was addressed to me during an online exam.The doubt is from Static Member Functions topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer» CORRECT option is (a) Even if class OBJECT is not created

Explanation: The static MEMBERS are property of class as a whole. There is no NEED of specific objects to call static members. Those can be called directly or with class name.
4.

Which among the following can’t be used to access the members in any way?(a) Scope resolution(b) Arrow operator(c) Single colon(d) Dot operatorI had been asked this question during an interview.I need to ask this question from Static Member Functions in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct answer is (C) Single colon

To explain I would SAY: The single colon can’t be USED in any way in order to ACCESS the static MEMBERS of a class. Other symbols can be used according to the code and need.

5.

The keyword static is used _______________(a) With declaration inside class and with definition outside the class(b) With declaration inside class and not with definition outside the class(c) With declaration and definition wherever done(d) With each call to the member functionI have been asked this question in a national level competition.The query is from Static Member Functions topic in section Exception Handling & Static Class Members of Object Oriented Programming

Answer» CORRECT choice is (b) With declaration inside class and not with definition outside the class

The best I can explain: The KEYWORD is USED only inside the class while declaring the static member. Outside the class, only definition with proper syntax is given. There is no need of SPECIFYING the keyword static again.
6.

Which keyword should be used to declare the static member functions?(a) static(b) stat(c) const(d) commonThe question was asked in an interview for job.My question comes from Static Member Functions in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer» RIGHT answer is (a) static

Easy explanation - The member functions which are to be made static, must be preceded with the keyword static. This INDICATES the compiler to make the functions common to all the objects. And a new COPY is not created with each of the new OBJECT.
7.

The static member functions _______________(a) Can’t be declared const(b) Can’t be declared volatile(c) Can’t be declared const or volatile(d) Can’t be declared const, volatile or const volatileI have been asked this question in my homework.This is a very interesting question from Static Member Functions in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right OPTION is (d) Can’t be DECLARED const, volatile or const volatile

For explanation: The static member functions can’t be made const, since any object or class itself should be capable of MAKING CHANGES to the function. And the function must RETAIN all changes common to all the objects.

8.

Which among the following is true?(a) Static member functions can be overloaded(b) Static member functions can’t be overloaded(c) Static member functions can be overloaded using derived classes(d) Static member functions are implicitly overloadedThe question was posed to me in class test.The origin of the question is Static Member Functions topic in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (b) Static MEMBER functions can’t be OVERLOADED

The explanation is: The static member functions can’t be overloaded because the definition MUST be the same for all the instances of a class. If an overloaded FUNCTION have many definitions, none of them can be made static.

9.

The static members are ______________________(a) Created with each new object(b) Created twice in a program(c) Created as many times a class is used(d) Created and initialized only onceThe question was posed to me by my college director while I was bunking the class.This intriguing question comes from Static Member Functions topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right option is (d) CREATED and initialized only once

Easiest EXPLANATION - The static MEMBERS are created only once. Then those members are REUSED whenever called or INVOKED. Memory is allocated only once.

10.

Which among the following is true?(a) Static member functions can’t be virtual(b) Static member functions can be virtual(c) Static member functions can be declared virtual if it is pure virtual class(d) Static member functions can be used as virtual in JavaThis question was posed to me in final exam.I'm obligated to ask this question of Static Member Functions in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct option is (a) STATIC member FUNCTIONS can’t be virtual

The explanation: The static member functions can’t be virtual. This is a restriction on static member functions, since the definition should not CHANGE or should not be overridden by any other function of derived class. The static MEMBERS must REMAIN same for all the objects.

11.

Which among the following is not applicable for the static member functions?(a) Variable pointers(b) void pointers(c) this pointer(d) Function pointersThis question was addressed to me during an interview.My question is based upon Static Member Functions in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct choice is (c) this pointer

The best EXPLANATION: Since the STATIC members are not property of objects, they doesn’t have this pointer. Every TIME the same MEMBER is referred from all the objects, hence use of this pointer is of no use.

12.

Which is correct syntax to access the static member functions with class name?(a) className . functionName;(b) className -> functionName;(c) className : functionName;(d) className :: functionName;The question was asked during an online interview.This question is from Static Member Functions topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct option is (d) className :: functionName;

EASIEST EXPLANATION - The scope resolution operator must be used to access the static member functions with CLASS name. This indicates that the function belongs to the CORRESPONDING class.

13.

The static member functions ____________________(a) Can be called using class name(b) Can be called using program name(c) Can be called directly(d) Can’t be called outside the functionI had been asked this question during an internship interview.This interesting question is from Static Member Functions topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (a) Can be called USING class NAME

For explanation: The static MEMBERS can be accessed using class name also. This is because the static members REMAIN common to all the objects. HENCE objects are not required.

14.

The static member functions __________________(a) Have access to all the members of a class(b) Have access to only constant members of a class(c) Have access to only the static members of a class(d) Have direct access to all other class members alsoI have been asked this question in class test.This intriguing question originated from Static Member Functions topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer» CORRECT answer is (c) Have access to only the static members of a CLASS

The explanation is: The static member functions are common for all the objects. These functions can use only the static members of a class in which those are defined. This is because other members CHANGE with respect to each object CREATED.
15.

Which among the following is correct definition for static member functions?(a) Functions created to allocate constant values to each object(b) Functions made to maintain single copy of member functions for all objects(c) Functions created to define the static members(d) Functions made to manipulate static programsI had been asked this question during an online interview.This is a very interesting question from Static Member Functions in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct choice is (B) FUNCTIONS made to maintain SINGLE copy of member functions for all objects

The explanation is: The functions which are made common, with respect to definition and data USAGE, to all the objects. These functions are ABLE to access the static data members of a class.

16.

Which among the following is wrong syntax related to static data members?(a) className :: staticDataMember;(b) dataType className :: memberName =value;(c) static dataType memberName;(d) className : dataType -> memberName;The question was posed to me in an interview.My doubt stems from Static Data Members topic in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct ANSWER is (d) CLASSNAME : dataType -> memberName;

Explanation: The syntax given in option d doesn’t belong to any PARTICULAR declaration or definition. First one is to access the static members USING the CLASS name. Second is to define the static data outside the class. Third syntax id to declare a data member as static in a class.

17.

If object of class are created, then the static data members can be accessed ____________(a) Using dot operator(b) Using arrow operator(c) Using colon(d) Using dot or arrow operatorThis question was addressed to me in my homework.My question is taken from Static Data Members topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right answer is (d) Using DOT or ARROW OPERATOR

For explanation: The static DATA members can be accessed in usual WAY as other members are accessed using the objects. The dot operator is used generally. Arrow can be used with the pointers.

18.

Whenever any static data member is declared in a class ______________________(a) Only one copy of the data is created(b) New copy for each object is created(c) New memory location is allocated with each object(d) Only one object uses the static dataThis question was posed to me in examination.My question is based upon Static Data Members topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer» RIGHT answer is (a) Only one copy of the data is created

The best I can explain: The static data is same for all the objects. Instead of creating the same data each TIME an object is created, the compiler created only one data which is accessed by all the objects of the CLASS. This saves memory and reduces redundancy.
19.

Which data members among the following are static by default?(a) extern(b) integer(c) const(d) voidI had been asked this question in semester exam.The origin of the question is Static Data Members topic in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (c) CONST

For explanation: The const DATA members of any class are made STATIC by default. This is an implicit meaning given by the compiler to the member. Since const values won’t CHANGE from object to object, hence are made static instead.

20.

Which among the following is the correct syntax to access static data member without using member function?(a) className -> staticDataMember;(b) className :: staticDataMember;(c) className : staticDataMember;(d) className . staticDataMember;This question was addressed to me by my college director while I was bunking the class.I'd like to ask this question from Static Data Members in section Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right choice is (b) className :: staticDataMember;

To explain I would say: For accessing the static data members without using the static MEMBER functions, the CLASS NAME can be USED. The class name FOLLOWED by scope resolution, indicating that static data members is member of this class, and then the data member name.

21.

The static data member __________________________(a) Can be accessed directly(b) Can be accessed with any public class name(c) Can be accessed with dot operator(d) Can be accessed using class name if not using static member functionThis question was addressed to me in an online interview.Enquiry is from Static Data Members in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right CHOICE is (d) Can be ACCESSED using class name if not using static member function

Easiest explanation - The static data members can be accessed using the class name also. If the member functions is not USED or is not to be used then we can call the static data members DIRECTLY by using its corresponding class name.

22.

If static data members have to be used inside a class, those member functions _______________(a) Must not be static member functions(b) Must not be member functions(c) Must be static member functions(d) Must not be member function of corresponding classI had been asked this question in exam.My enquiry is from Static Data Members topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right option is (C) Must be static member functions

The EXPLANATION is: Only the static member functions can ACCESS the static data members. The definition of static members is MADE common and hence the member function should be capable of manipulating the static data members.

23.

The syntax for defining the static data members is __________(a) dataType className :: memberName = value;(b) dataType className : memberName = value;(c) dataType className . memberName = value;(d) dataType className -> memberName =value;I had been asked this question in an interview for job.My question is taken from Static Data Members in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct ANSWER is (a) dataType className :: memberName = value;

To explain I would say: The syntax doesn’t contain the static keyword. SINCE it is already been declared as static inside the class. The data type and the corresponding class name MUST be there to allocate the VARIABLE to a class. The value is assigned using scope resolution operator for the member name.

24.

The static data member ______________________(a) Must be defined inside the class(b) Must be defined outside the class(c) Must be defined in main function(d) Must be defined using constructorThis question was addressed to me during an online exam.This question is from Static Data Members topic in section Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right option is (b) MUST be defined outside the CLASS

Explanation: The static data members must be defined outside the class. Since these are common to all the objects and should be created only once, they must not be defined in the CONSTRUCTOR.

25.

Which is the correct syntax for declaring static data member?(a) static mamberName dataType;(b) dataType static memberName;(c) memberName static dataType;(d) static dataType memberName;I had been asked this question during an interview for a job.The query is from Static Data Members topic in section Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (d) static dataType memberName;

For explanation: The syntax must firstly be mentioned with the KEYWORD static. Then the DATA TYPE of the member followed by the member name should be given. This is general form of declaring static data MEMBERS.

26.

Any changes made to static data member from one member function _____________(a) Is reflected to only the corresponding object(b) Is reflected to all the variables in a program(c) Is reflected to all the objects of that class(d) Is constant to that function onlyI had been asked this question in a job interview.This is a very interesting question from Static Data Members topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The CORRECT choice is (C) Is reflected to all the objects of that class

The BEST explanation: The changes made from any function to static data member will be a COMMON change for all the other objects also. If the change is made with respect to one object and change is printed from another object, the RESULT will be same.

27.

Which keyword should be used to declare static variables?(a) static(b) stat(c) common(d) constThis question was posed to me in an interview for internship.I'm obligated to ask this question of Static Data Members in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer» CORRECT option is (a) static

To explain I would say: The KEYWORD USED to declare static variables is static. This is MUST be used while declaring the static variables. The COMPILER can make variables static if and only if they are mentioned with static keyword.
28.

Which among the following best defines static variables members?(a) Data which is allocated for each object separately(b) Data which is common to all the objects of a class(c) Data which is common to all the classes(d) Data which is common to a specific methodThe question was posed to me at a job interview.I'd like to ask this question from Static Data Members in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct option is (b) Data which is common to all the OBJECTS of a class

Best explanation: The static data members are made common to all the OBJECT of a class. They doesn’t CHANGE from object to object. Those are property of class rather than of any INDIVIDUAL object.

29.

Which condition among the following might result in memory exception?(a) False if conditions(b) Nested if conditions that are all false(c) Infinite loops(d) Loop that runs exactly 99 timesI got this question in unit test.I want to ask this question from Catching Class Types topic in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct answer is (c) Infinite loops

To explain I would say: The infinite loops doesn’t stop running once started. There MUST be a way to stop the loop but that is always an IMPROPER termination. Infinite loops may keep on USING more MEMORY and hence would RESULT in memory error.

30.

Only the base class catch box can handle more than one exception in single block.(a) True(b) FalseThis question was posed to me in exam.Origin of the question is Catching Class Types in section Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right answer is (B) False

Explanation: There is no specific condition that states that only BASE class CATCH box can handle more than one exception in single box. Even the derived class catch CLOCKS can handle more than one EXCEPTIONS.

31.

Which is the necessary condition to define the base and derived class catch blocks?(a) Base class catch should be defined first(b) Derived class catch should be defined first(c) Catch block for both the classes must not be defined(d) Catch block must be defined inside main functionThe question was posed to me in final exam.The above asked question is from Catching Class Types in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (b) Derived CLASS catch should be defined first

Explanation: The derived class catch BLOCKS must be defined prior to the base class catch BLOCK. This is to ensure that all the catch boxes are reachable. If not done, the code might become unreachable which in TURN makes the program prone to errors.

32.

Which among the following is true?(a) Only the base class catch blocks are important(b) Only the derived class catch blocks are important(c) Both the base and derived class catch blocks are important(d) If base and derived classes both produce exceptions, program doesn’t runI got this question in homework.Asked question is from Catching Class Types topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right option is (c) Both the base and derived class CATCH blocks are important

The best I can explain: The PURPOSE of EXCEPTION handling is to handle the unexpected errors in the program. If base class might PRODUCE some error then its catch block MUST be given and if the derived class might produce some error then it must be given a specific catch block too.

33.

If classes produce some exceptions, then ______________________(a) Their respective catch block must be defined(b) Their respective catch blocks are not mandatory(c) Their catch blocks should be defined inside main function(d) Their catch blocks must be defined at the end of programI had been asked this question in an interview for internship.The question is from Catching Class Types topic in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct choice is (a) Their respective catch BLOCK must be defined

The explanation: The catch blocks must be defined. This is to ensure that all the EXCEPTIONS related to the CLASSES are HANDLED by the program code and the program doesn’t terminate unexpectedly.

34.

Which among the following handles the undefined class in program?(a) ClassNotFound(b) NoClassException(c) ClassFoundException(d) ClassNotFoundExceptionI had been asked this question in an interview for internship.The above asked question is from Catching Class Types in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct option is (d) ClassNotFoundException

The best I can explain: It is the exception handler that handles the EXCEPTIONS when the class used is not found in the program. This is DONE to HANDLE all the undefined class exceptions. This can be due to a command LINE error.

35.

If a catch block accepts more than one exceptions then __________________(a) The catch parameters are not final(b) The catch parameters are final(c) The catch parameters are not defined(d) The catch parameters are not usedI got this question in final exam.Question is from Catching Class Types topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer» RIGHT answer is (b) The catch PARAMETERS are final

To EXPLAIN: The catch parameters are made final. This is to ensure that the parameters are not changed INSIDE the catch block. Hence those RETAIN their values.
36.

To catch more than one exception in one catch block, how are the exceptions separated in the syntax?(a) Vertical bar(b) Hyphen(c) Plus(d) ModulusThe question was posed to me in an internship interview.I need to ask this question from Catching Class Types topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer» CORRECT choice is (a) VERTICAL bar

To EXPLAIN I would say: Just the way we separate the ARGUMENTS in a function definition using comma. Here we separate the exceptions by using a vertical bar or we call it pipe symbol SOMETIMES. This is just a convention followed to separate different exception list.
37.

Since which version of java is multiple exception catch was made possible?(a) Java 4(b) Java 5(c) Java 6(d) Java 7This question was addressed to me in an international level competition.This interesting question is from Catching Class Types in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct answer is (d) Java 7

Best explanation: None of the languages used to SUPPORT multiple EXCEPTION CATCH in a SINGLE catch block. Since java 7 the feature was added to catch more than one exceptions in one catch block.

38.

How many catch blocks can a class have?(a) Only 1(b) 2(c) 3(d) As many as requiredI have been asked this question during an interview.Enquiry is from Catching Class Types in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct option is (d) As MANY as required

The best explanation: There are many type of EXCEPTIONS that may arise while running a code. And each catch block can handle only one exception. HENCE there can be as many catch blocks as required.

39.

If catching of base class exception is done before derived class in C++ ________________(a) It gives compile time error(b) It doesn’t run the program(c) It may give warning but not error(d) It always gives compile time errorThis question was posed to me during a job interview.My question is taken from Catching Class Types topic in section Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct choice is (c) It may give warning but not error

Easy explanation - The compiler in C++ doesn’t IDENTIFY this as COMPILE time error and allows the execution of the PROGRAM. But, the compiler may give some warning RELATED to the catch block sequence or code unreachable.

40.

The catching of base class exception ___________________________ in java.(a) After derived class is not allowed by compiler(b) Before derived class is not allowed by compiler(c) Before derived class is allowed(d) After derived class can’t be doneI had been asked this question during an internship interview.I'd like to ask this question from Catching Class Types in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct CHOICE is (b) Before derived class is not allowed by compiler

For explanation: The catching of base class exception before derived class is not allowed in java. The compiler itself doesn’t allow this declaration. It PRODUCES an ERROR.

41.

Which among the following is true?(a) If catch block of base class is written first, it is compile time error(b) If catch block of base class is written first, it is run time error(c) If catch block of base class is written first, derived class catch block can’t be reached(d) If catch block of base class is written first, only derived class catch block is executedI got this question in an interview.This interesting question is from Catching Class Types in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (c) If catch block of base CLASS is WRITTEN FIRST, DERIVED class catch block can’t be reached

Best explanation: If the catch block of the base class is defined first and then the derived class catch block is given. The code becomes unreachable. HENCE the derived class catch block must be written first.

42.

If both base and derived class caught exceptions ______________(a) Then catch block of derived class must be defined before base class(b) Then catch block of base class must be defined before the derived class(c) Then catch block of base and derived classes doesn’t matter(d) Then catch block of base and derived classes are not mandatory to be definedThe question was posed to me during a job interview.This key question is from Catching Class Types in section Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct option is (a) Then catch block of derived class must be DEFINED before base class

The EXPLANATION is: It is a condition for WRITING the catch BLOCKS for base and derived classes. It is mandatory to write derived class catch block first because the errors produced by the derived class must be handled first.

43.

Which among the following is true for class exceptions?(a) Only base class can give rise to exceptions(b) Only derived class can give rise to exceptions(c) Either base class or derived class may produce exceptions(d) Both base class and derived class may produce exceptionsThe question was posed to me in a job interview.I would like to ask this question from Catching Class Types topic in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct answer is (d) Both BASE class and derived class may PRODUCE exceptions

For explanation: It’s not mandatory that either base class or derived class can give rise to exceptions. The exceptions might GET produced from any class. The exceptions depends on code.

44.

Why do we use finally block?(a) To execute the block if exception occurred(b) To execute a code when exception is not occurred(c) To execute a code whenever required(d) To execute a code with each and every run of programThe question was asked at a job interview.My enquiry is from Exception Handling topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (d) To execute a code with each and every run of program

For EXPLANATION: Sometimes there is a need to execute a set of code every time the program RUNS. Even if the exception occurs and even if it doesn’t, there can be some code that must be executed at end of the program. That code is written in finally block. This block is ALWAYS executed REGARDLESS of exceptions OCCURRING.

45.

Which class is used to handle the input and output exceptions?(a) InputOutput(b) InputOutputExceptions(c) IOExceptions(d) ExceptionsIOThe question was asked in an interview.The doubt is from Exception Handling in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct answer is (c) IOExceptions

Explanation: There is a specific class to handle each type of exceptions that might be PRODUCED in a PROGRAM. The INPUT and output exceptions can be handled by an object of class IOExcceptions. This class HANDLES all type of input and output exceptions.

46.

Which symbol should be used to separate the type of exception handler classes in a single catch block?(a) ?(b) ,(c) –(d) |The question was posed to me in a job interview.My question comes from Exception Handling topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer» RIGHT CHOICE is (d) |

The explanation is: A pipe symbol can be used to separate different type of EXCEPTIONS. The exceptions should always be given in proper sequence to ensure that no code remains unreachable. If not done properly the code might NEVER be used in a program.
47.

Multiple catch blocks __________________(a) Are mandatory for each try block(b) Can be combined into a single catch block(c) Are not possible for a try block(d) Can never be associated with a single try blockI have been asked this question in unit test.My question is based upon Exception Handling in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct CHOICE is (b) Can be combined into a SINGLE catch block

Best explanation: The separate catch blocks for a single try block can be combined into a single catch block. All TYPE of errors can be then handled in s single block. The type STILL have to be specified for the errors that might be produced.

48.

To catch the exceptions ___________________(a) An object must be created to catch the exception(b) A variable should be created to catch the exception(c) An array should be created to catch all the exceptions(d) A string have to be created to store the exceptionThe question was posed to me in quiz.My enquiry is from Exception Handling in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct CHOICE is (a) An object MUST be created to catch the exception

To explain I would SAY: The object must be created of a specific class of which the error has occurred. If the type of error is unknown then we can USE an object of class Exceptions. This object will be able to handle any kind of exception that a program MIGHT produce.

49.

Which among the following is not a method of Throwable class?(a) public String getMessage()(b) public Throwable getCause()(c) public Char toString()(d) public void printStackTrace()This question was posed to me in an internship interview.Enquiry is from Exception Handling topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer» CORRECT CHOICE is (c) public Char TOSTRING()

The best I can explain: Actually all the functions are available in throwable class. But the return type given in the option is WRONG. The function toString RETURNS string value. Hence the return type must be a String and not a char.
50.

How many catch blocks can a single try block can have?(a) Only 1(b) Only 2(c) Maximum 127(d) As many as requiredI have been asked this question in exam.Enquiry is from Exception Handling topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct answer is (d) As MANY as required

Explanation: There is no LIMIT on the number of catch blocks corresponding to a try block. This is because the error can be of any type and for each type, a new catch block can be DEFINED. This is to make sure all type of EXCEPTIONS can be handled.