• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this code legal ?

 
Sanket Modi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this legal ?
1.
class ExceptionA extends Exception {}
class ExceptionB extends ExceptionA {}
class A{
void thrower() throws ExceptionA{
throw new ExceptionA();
}
}
public class B extends A{
void thrower() throws ExceptionB{
throw new ExceptionB();
}
}

2.
class ExceptionA extends Exception {}
class ExceptionB extends ExceptionA {}
public class Test{
void thrower() throws ExceptionA{
throw new ExceptionA();
}
public static void main(String[] args){
Test t = new Test();
try{t.thrower();}
catch(ExceptionB e) {}
}
}

can nayone explain me about this kind of codes?
 
Gilles Marceau
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

are you familiar with the concept of Exception in java ? This is
a prerequesite to understand this code. If so, could you be more
accurate and point out the thing you don't understand here ?

Gilles
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess that with "is it legal" you really mean "does it compile". You can find that out very quickly by trying to compile it and see if you get any errors.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic