Kindly clear the doubts of every question below...
i m marking them in serial no. do refer while giving the answer
thanx
----------------
1) public class Test9 extends A{
public static void main(
String args[]) throws Exception{
Test9 t = new Test9();
}
}
class A{
A() throws Exception{
System.out.println("A Class");
}
}
���������������.Compile error
why this answer ?
=========================================================
2)
public class ThrowsDemo {
static void throwMethod() throws Exception {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwMethod();
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
}
}
}
Answer :=> The method is throwing Exception but while catching your catching a subclass of Exception.
But the catching class is the same as the orginal one throws ..will it not work ?
=========================================================
3)
public class BettyAck {
public static void main(String argv[]){
BettyAck b =new BettyAck();
}
public BettyAck() {
Integer x = new Integer(10);
findOut(x);
Integer y = new Integer(99);
Integer z = y;
z = null;
findOut(y);
//here
}
public void findOut(Integer y){
y = null;
}
}
No obj are garbage collected.
why ?
============================================================
4)
public class CDummy
{
public static void main(String args[])
{
try {
int i=testX();
}
catch (Exception ee)
{
System.out.println("Exception !");
}
}
public static int testX() throws ArithmeticException
{
try {
throw new ArithmeticException();
}
finally {
System.out.println("Finally");
return 4;
}
}
}
when compile it complains that ...
CDummy.java:22: warning: finally clause cannot complete normally
}
^
1 warning
why ???
can return statement is not allowed in finally block ?
==========================================================
5)
try {
System.out.println("Test !");
}
catch(InterruptedException ee) {
System.out.println("The main
thread was interrupted !");
}
what is the result when compile ?
Answer :=
The code does not compile because the exception InterruptedException is never thrown. (InterruptedException is checked)
why ? if it is check then it must be definetly thrown ? confused
========================================================
6)
class A extends Thread {
public void run() {
try {
synchronized (this) {
wait();
}
} catch (InterruptedException ie) {
System.out.print(interrupted());
}
}
public static void main(String[] args) {
A a1 = new A();
a1.start();
a1.interrupt();
}
}
when compile and run the output is "false"
why ? when it is interupted and method interrupted() will return boolean ... as it actually been intruppted then why its false and not true ?
==========