Call protected method from a subclass of another instance of different packages

后端 未结 2 1795
遇见更好的自我
遇见更好的自我 2020-12-09 14:02

I want to invoke a protected method of another instance from within a subclass of the class providing this protected method. See the following example:

publi         


        
2条回答
  •  悲&欢浪女
    2020-12-09 14:29

    You could access the protected methods either by subclassing and overriding; also when they are available in the same package. I will add some details. You can read details here.

    The example that you have is on lines of the protected clone() method available in the Object class in java; you cannot directly call it on any object (although all object implicitly extend from the Object class).

提交回复
热议问题