This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from Dan Mock Exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question from Dan Mock Exam" Watch "Question from Dan Mock Exam" New topic
Author

Question from Dan Mock Exam

suresh kamsa
Ranch Hand

Joined: Jul 30, 2001
Posts: 149
class ColorException extends Exception {}
class WhiteException extends ColorException {}
abstract class Color {
abstract void m1() throws ColorException;
}
class White extends Color {
void m1() throws WhiteException {throw new WhiteException();}
public static void main (String[] args) {
White white = new White();
int a,b,c,d;
a = b = c = 0;
try {
white.m1();
a++;
} catch (WhiteException e) {b++;}
finally {c++;}
System.out.print(a+","+b+","+c);
}
}
Step by step Analysis, Please correct me.
-----------------------------------------
class ColorException extends Exception {}
ColorException is subclass of Excpetion
class WhiteException extends ColorException {}
WhiteExcpetion is subclass of ColorException
abstract class Color {
abstract void m1() throws ColorException;
What is going on here? Please explain.Is the method m1() going to use ColorException class?
}
class White extends Color {
White is subclass of Color
void m1() throws WhiteException {throw new WhiteException();
What is going on here? Please explain. Is method m1()goint to use some oneWhiteException?
}
public static void main (String[] args) {
White white = new White();
int a,b,c,d;
a = b = c = 0;
try {
white.m1();
which method will get called?
1.abstract void m1() or
2. void m1() Please explain
from down I know whats going on
a++;
} catch (WhiteException e) {b++;}
finally {c++;}
System.out.print(a+","+b+","+c);
}
}

I really appreciate. Thanks.
zarina mohammad
Ranch Hand

Joined: Jun 26, 2002
Posts: 104

[ August 22, 2002: Message edited by: zarina mohammad ]
suresh kamsa
Ranch Hand

Joined: Jul 30, 2001
Posts: 149
Why is it going to through exception? Any takers?
suresh kamsa
Ranch Hand

Joined: Jul 30, 2001
Posts: 149
void m1() throws WhiteException {throw new WhiteException();}
class White cannot through WhiteException?
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
I think that Zarina's post demonstrates that White.m1 throws an Exception and that causes the "catch" clause to be processed.

[ August 22, 2002: Message edited by: Dan Chisholm ]

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from Dan Mock Exam
 
Similar Threads
Exception Question from Dan Chisholm
An Exception question in Dan's mock exam
danchisholm.net exam3 Question 6
Unreachable statements
Exception- Doubt Help Please....