File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JavaCap no. 10" Watch "JavaCap no. 10" New topic

JavaCap no. 10

may leung

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 {
} 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{..."

may leung

Joined: Nov 28, 2000
Posts: 23
Thank you!!
subject: JavaCap no. 10
It's not a secret anymore!