aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes   Is this code legal ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "  Is this code legal ?" Watch "  Is this code legal ?" New topic
Author

Is this code legal ?

Sanket Modi
Ranch Hand

Joined: Mar 10, 2008
Posts: 30
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?


Thanks and regards,<br />SanKet Modi
Gilles Marceau
Ranch Hand

Joined: Feb 17, 2007
Posts: 78
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


SCJP 1.5<br />SCJD 1.6<br />SCBCD in progress...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14144
    
  18

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is this code legal ?