This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Java Caps Mock" Watch "Java Caps Mock" New topic
Author

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 {
throwMethod();
} 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
hi,
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...
 
 
subject: Java Caps Mock