Search code examples
javainheritancejsoupabstractextend

java - extend a class to a library superclass


I need to extend my own class to a library class (org.jsoup.nodes.Node). The superclass is abstract and contains abstract methods. My problem is that some of these abstract methods have no modifier, which mean that by default I have no access and I can't override them. When I try to do it I have this message:

Method does not override method from its superclass

How could I solve this problem?


Solution

  • A method with no access modifier is package-private. The only way to subclass the class you reference is to declare your class in the package org.jsoup.nodes, so it's in the same package.

    package org.jsoup.nodes;
    
    class MyNode extends Node {
        // ...
    }
    

    Nothing actually prevents your doing that.

    But given that the class declares package-private members, it's probably not meant to be subclassed outside the library.