This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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!!
I agree. Here's the link:
subject: JavaCap no. 10
jQuery in Action, 3rd edition