*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JavaCap no. 10 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JavaCap no. 10" Watch "JavaCap no. 10" New topic
Author

JavaCap no. 10

may leung
Greenhorn

Joined: Nov 28, 2000
Posts: 23
anyone can help to solve this out?
public class ThrowsDemo {
static void throwMethod() {
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);
}
}
}
A) Compilation error
B) Runtime error
C) Compile successfully, nothing is printed.
D) inside demoMethod. followed by caught: java.lang.IllegalAccessExcption: demo

ans. is A But I don't understand!
Thank you
Aniruddha Mukhopadhyay
Ranch Hand

Joined: Nov 15, 2000
Posts: 59
Hi May,
It cannot compile because method throwMethod() has lines "throw new IllegalAccessException("demo")" in it's code, but does not declare that in the beginning. It can be made to compile by making declaration of method to start by "static void throwMethod() throws IllegalAccessException{..."
Aniruddha


Aniruddha
may leung
Greenhorn

Joined: Nov 28, 2000
Posts: 23
Thank you!!
 
 
subject: JavaCap no. 10
 
Similar Threads
Exception doubt
Compile Error
Java Caps Mock
throw an Exception....
Exception Q?