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 Java Caps Mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Java Caps Mock" Watch "Java Caps Mock" New topic

Java Caps Mock

Vijay Narayanan
Ranch Hand

Joined: Sep 09, 2001
Posts: 50
What is the result when you compile and run the following code?
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 throwMethod. followed by caught:
java.lang.IllegalAccessExcption: demo

The result given is A but i feel it should be D
any comments...

<b>Sun Certified Java Programmer</b> <i>for the Java 2 Platform</i><br /><b>PMP</b>
Tony Sam
Ranch Hand

Joined: Nov 19, 2001
Posts: 32
When you throw an exception in a method,the exception must be declared to be thrown,such as :
static void throwMethod() throws IllegalAccessException{}
hope this can helps

Tony Sam<BR>One want to be a SCJP...
I agree. Here's the link:
subject: Java Caps Mock
It's not a secret anymore!