What will be the output of the following java code?
public class Test {
public int check(int a) {
if (a > 10)
return a % 10;
int x = 0;
try {
if (a % 2 == 0)
throw new Exception("this is not even number");
else
return x;
} catch (Exception e) {
return 5;
} finally {
return 6;
}
}
public static void main(String args[]) {
int data = 50, value = 6;
Test t = new Test();
int m = t.check(value);
switch (m) {
case 5:
data = data * 2;
case 6:
data = data * 2;
case 7:
data = data + data;
default:
}
System.out.println(data);
}
}
What will be the output of the following java code?
class ParentException extends Throwable {
}
class ChildException extends ParentException {
}
public class Test {
void helloMethod() throws ParentException {
throw new ChildException();
}
public static void main(String[] args) {
Test t = new Test();
try {
t.helloMethod();
} catch (ParentException pe) {
System.out.println("ParentException will be thrown");
} catch (ChildException ce) {
System.out.println("ChildException1 will be thrown");
} finally {
System.out.println("completed");
}
}
}
What will be the output of the following java code?
public class Test {
public static void main(String args[]) {
try {
hello();
} catch (IndexOutOfBoundsException ex) {
System.out.println("1");
throw new NullPointerException();
} catch (NullPointerException ex1) {
System.out.println("2");
return;
} catch (Exception ex2) {
System.out.println("3");
} finally {
System.out.println("4");
}
System.out.println("End");
}
public static void hello() {
System.out.println("hello method");
throw new IndexOutOfBoundsException("outOfBoundException");
}
}
What will be the output of the following java code?
public class Test {
public String hello(String str) {
if (str.length() == 0 || str == null) {
return "empty";
} else {
return "there have data";
}
}
public static void main(String[] args) {
Test t = new Test();
t.hello(null);
}
}
What will be the output of the following java code?
public class Test {
public static void main(String args[]) {
try {
if (args.length == 0) {
return;
} else {
throw new Exception("No data Found");
}
} catch (Exception ex) {
System.out.println("Main Exception");
} finally {
System.out.println("Completed");
}
}
}