private method in inheritance in Java

前端 未结 6 1322
臣服心动
臣服心动 2020-12-03 19:38

I have confusion about using private methods in inheritance, for example:

public class A {
    private void say(int number){
        System.out.print(\"A:\"+         


        
6条回答
  •  独厮守ぢ
    2020-12-03 20:07

    If you want a subclass to have access to a superclass method that needs to remain private, then protected is the keyword you're looking for.

    • Private allows only the class containing the member to access that member.
    • Protected allows the member to be accessed within the class and all of it's subclasses.
    • Public allows anyone to access the member.

提交回复
热议问题