Say I have a interface:
public interface Foo
{
}
and a base class
public class Baseclass
{
}
and the following subclass
public class Subclass extends Baseclass implements Foo
{
public SubClass(BaseClass base)
{
super(base); // call copy constructor
// initiatize subclass specific variables
}
}
Assuming I have an instance of subclass and I pass it to a method that accepts Baseclass
, am I allowed to cast the Baseclass
to Foo
even though the base class itself doesn't implement the interface?
Foo foo = (Foo) Baseclass; // is this allowed?