Interface/Exception Question

I just thought about this and wonder if i am right:

public interface Abc()

{

doinSmth();

}

public class Cde() implements Abc

{

doinSmth() //throws Exception won't work, got to catch it

{

// code that throws exception

}

}

public class Unknown(Abc cde_instance)

{

// doinSmth is used here

}

Because cde is used in Unknown as Abc and Abc doesn't throw

Exception, Cde is not allowed to throw it. That means all Exceptions

got to be catched in Cde. Right?

[569 byte] By [mischka24] at [2007-9-27 22:34:54]
# 1
Just because you are referring to it as a type of the base class (Abc) doesn't mean that it is no longer a type of the derived class (Cde). So it will still throw any exceptions that get thrown by any Cde object.
erikprice at 2007-7-7 13:18:04 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
Yes, you will have to catch all the exceptions in doinSmith(). doinSmith() cannot throw an exception.
Brian-74-454 at 2007-7-7 13:18:04 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

Cde can throw an excpetion... but, a method in Cde that is overriding a another method (in this case doinSmith() from Abc) that does not throw an exception, the method cannot throw an excpetion either. When overriding a method, the parameter list must be the same as the method it is overriding, the method cannot be more private than the method it is overriding, the return type must be the same, and any exceptions throw by that class must be of the same class or a subclass of the same class that is throw by the parent method.

Brian-74-454 at 2007-7-7 13:18:04 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4
Except constructors.(that's a pun too)
erikprice at 2007-7-7 13:18:04 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5
AHAHA... geek humor.
Brian-74-454 at 2007-7-7 13:18:04 > top of Java-index,Archived Forums,New To Java Technology Archive...