Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Question from Dan Mock Exam

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ August 22, 2002: Message edited by: zarina mohammad ]
 
suresh kamsa
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is it going to through exception? Any takers?
 
suresh kamsa
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
void m1() throws WhiteException {throw new WhiteException();}
class White cannot through WhiteException?
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic