Question-61. Can I import same package/class twice? Will the JVM load the package twice at runtime ?

Answer- One can import the same package or same class multiple times. Neither compiler nor JVM complains about it. But the JVM will internally load the class only once no matter how many times you import the same class.

Question-62. What is static import ?

Answer- By static import, we can access the static members of a class directly, there is no to qualify it with the class name.

Question-63. What is Exception Handling

Answer- Exception Handling is a mechanism to handle runtime errors.It is mainly used to handle checked exceptions.

Question-64. What is difference between Checked Exception and Unchecked Exception ?

Answer-

 1)Checked Exception

The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions 
e.g.IOException,SQLException etc. Checked exceptions are checked at compile-time.

2)Unchecked Exception

The classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException,
NullPointerException etc. Unchecked exceptions are not checked at compile-time.

 

Question-65. What is the base class for Error and Exception ?

Answer- Throwable.

Question-66. Is it necessary that each try block must be followed by a catch block ?

Answer- It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.

Question-67. What is finally block? ?

Answer- finally block is a block that is always executed.

Question-68. Can finally block be used without catch ?

Answer- Yes, by try block. finally must be followed by either try or catch.

Question-69. Is there any case when finally will not be executed ?

Answer- finally block will not be executed if program exits(either by calling System.exit() or by causing a fatal error that causes the process to abort).

Question-70. What is difference between throw and throws ?

Answer-

throw:  It is explicitly used to throw an exception.
    throw is followed by an instance.
    It is used within a method.
    You cannot throw multiple exceptions.

throws: Used to declare an exception.
      It is followed by a class.
      Used within a method signature.
You can declare multiple exception e.g. public void method()throws IOException,SQLException.