Correct Answer : Get Lastest Questions and Answer : Explanation: As soon as jvm reaches 10/0 it will ignore all the statement after that throw exception and directly goes to in respective catch block . Hence, it will
print 2 and then just after that it will go to finally block and print 3. Last line of the method will not be called because there is a return; statement in method which will send control out of method. If you remove return; statement it will print 2 3 4.
Question : You have been given below code, please select correct behavior of it
package com.hadoopexam;
import java.util.Scanner;
class Welcome { public static void main(String[] args) { try (Scanner scanner = new Scanner(System.in)) { scanner.close(); scanner.close(); } } } 1. It will not compile
2. It will compile but run time , it will throw IllegalStateException
Closes this scanner. If this scanner has not yet been closed then if its underlying readable also implements the java.io.Closeable interface then the readable's close method will be invoked. If this scanner is already closed then invoking this method will have no effect. Attempting to perform search operations after a scanner has been closed will result in an IllegalStateException. So here we are calling close() method 3 times. One with try resource, so automatically called in finally clause and 2 times explicitly we are calling it.
Question : You have been given below code, what happen if you execute it. package com.hadoopexam;
Correct Answer : Get Lastest Questions and Answer : Explanation: By default assertions are disabled. Hence, here it will not print anything. If you enable assertion than it will print Error. Because AssetionError is a subclass of Error.