it would probably have been better to use the appropriate Enthuware forum to report the issue.
Another alternative is to catch this exception in myMethod:
Further, since a call to myMethod cannot throw Exception anymore, main method does not need to declare it either.
Roel De Nijs wrote:
Kamil Hlubek wrote:To be more precisely: The class BlackInk inherits from Ink, but nobody of them implements the Printable interface, so it should not compile in my opinion, because the reference's variable type and the type to cast to are in different hierarchys
The only reason why the above code compiles, is because the BlackInk class is not final. That means somebody can create a subclass which implements the Printable interface, like And then it's perfectly valid to change line8 toAnd then the TwistInTaleCasting class will compile successfully and execute without any runtime exceptions.
And as you probably already have understood from this explanation, if you would change the BlackInk class declaration toyou'll get the "incompatible types" compiler error.
For more detailed information have a look at this thread (about exactly the same code snippet), this thread (also similar code snippet and an additional one) and this thread (about casting or using instanceof operator on a class vs an interface).
Hope it helps!
Kind regards,
Roel
An interface’s variables are implicitly public, final & static. They should be assigned at declaration. It’s methods are implicitly public and they can’t be final or static.