Select chapter


Sponsored Links



      Submit a Question Submit Paper

0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Fresher interview question

2
While opening a file in java, what kind of exceptions may occur?
Toughnessemptystaremptystaremptystaremptystaremptystar
  1. FileNotFoundException, which is an unchecked exception.
  2. FileNotFoundException, which is a checked exception.
  3. There won't be any exception when we are opening a file.
  4. none
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
3
What is exception class hierarchy?
Toughnessemptystaremptystaremptystaremptystaremptystar
  1. Throwable is the base class, with Error and Exception as its immediate derived classes.
  2. Throwable is the base class, with Error, Exception, and RunTimeException as its immediate derived classes.
  3. RunTimeException is the immediate derived class of Exception class.
  4. both option 1 and 3 are correct.
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
4
What is an exception?
Toughnessemptystaremptystaremptystaremptystaremptystar
  1. An exception is an event that occurs during the execution of a program that disrupts the normal flow of program execution.
  2. Exception can occur at compile time also, which are known as compile time exceptions.
  3. option 2 is correct. The exceptions that occur at run time belongs to RunTimeException class. Normal compile time exceptions belongs to Exception class.
  4. all are true.
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Fresher interview question

5
When does a finally block will get executed?
Toughnessemptystaremptystaremptystaremptystaremptystar
  1. finally block will be executed after try block with out fail, only if an exception occurs.
  2. finally block will not be executed if an exception occurs.
  3. finally block will not be executed if an uncaught exception occurs in that try block.
  4. finally block will be executed after try block with out fail, even if an exception occur or doesn't occur.
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
7
How to handle ArrayIndexOutOfBoundsException in java?
How do you handle the exception thrown by below program?
public class ExceptionDemo {
        public static void main(String[] args) {
                int[] arr = new int[10];
                arr[10] = 10;
        }
}
Toughnessemptystaremptystaremptystaremptystaremptystar
  1. Since it throws ArrayIndexOutOfBoundsException which is an unchecked exception, we don't need to worry about it as it is not mandatory to handle it.
  2. We have to put try{ .. }catch(ArrayIndexOutOfBoundsException e){..} to handle this exception.
  3. there is no exception in this program to handle.
  4. Since it throws ArrayIndexOutOfBoundsException which is an unchecked exception, we should not handle it by using try-catch block, rather we have to debug this program and fix that issue.
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Fresher interview question

8
Is it possible to handle multiple exceptions in a single catch block?
Toughnessemptystaremptystaremptystaremptystaremptystar
  1. Yes, you can do it by using | operator (bit wise Or'ing operator)
  2. No, a catch block can handle only one exception at a time.
  3. Yes, you can handle multiple exceptions in a catch block by using , (coma) operator.
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
9
What kind of exception below Java program will throw?
class Test{
        int i=10;
        public void disp(){
                System.out.println("i val is.."+i);
        }
}
public class ExceptionDemo {
        public static void main(String[] args) {
                Test t=null;
                t.disp();
        }
}
Toughnessemptystaremptystaremptystaremptystaremptystar
  1. It will not throw any exception, but it may give compile time error.
  2. It will throw NullPointerException, which is a checked exception.
  3. It will throw, NullPointerException, which is an un-checked exception.
  4. it will print i val is..10
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Fresher interview question

12
What is rethrowing an exception?
Toughnessemptystaremptystaremptystaremptystaremptystar
  1. Some times there may be situations where after handling an exception in catch block, we may have to throw it back to parent function as well, this is called as rethrowing.
  2. When we can't handle a checked exception, then we use Throws clause to throw it back to parent function, this is called as rethrowing.
  3. Some times there may be situations where after handling an exception in catch block, we may have to stop the program by returning.this is called as rethrowing.
  4. When we don't handle a checked exception, then it will be automatically thrown to previous function, this is called as rethrowing.
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Fresher interview question

14
What is the use of having try-with-finally, with out any catch block?
Toughnessemptystaremptystaremptystaremptystaremptystar
  1. There is no use case as such.
  2. There may be situations where we have to release system resources carefully, and our code is full of loops, return, and break statements. In those scenarios we can use finally block to make sure that all resources will be released properly.
  3. We can't use try with out catch block.
  4. We can use try with finally block but at least one catch block should be there.
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Show Answer and Explanation
Share it onFacebook gmail Twitter
0 Says Important
0 People Like it
RateToughnessemptystaremptystaremptystaremptystaremptystar
Show Answer and Explanation
Share it onFacebook gmail Twitter