private method in inheritance in Java

前端 未结 6 1323
臣服心动
臣服心动 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 19:58

    Subclasses can only invoke or override protected or public methods (or methods without access modifiers, if the superclass is in the same package) from their superclasses. private methods stay in the class in which they're declared and aren't visible to any other class, no matter how it's related.

提交回复
热议问题