Is it possible to unimplement an interface in derived class in Java?

java, oop

Solution

No it is not possible, and your intent to do so is a good hint that something is flawed in your class hierarchy.

Workaround: change the class hierarchy, eg. like this:

interface SomeInterface {}
abstract class AbstractParentClass {}
class ParentClass extends AbstractParentClass implements SomeInterface {}
class ChildClass extends AbstractParentClass {}

Problem

Let's have the following class hierarchy: ``` public class ParentClass implements SomeInterface { } public class ChildClass extends ParentClass { } ``` Then let's have these two instances: ``` ParentClass parent; ChildClass child; ``` Then we have the following TRUE statements ``` (parent instanceof SomeInterface) == true (child instanceof SomeInterface) == true ``` Is it possible to unimplement the SomeInterface in the ChildClass, so when we check with the instanceof operator it returns false? If not possible, is there a workaround?

Original source