子类可以在Java中继承哪些方法? [英] Which methods can a subclass inherit in Java?

查看:132
本文介绍了子类可以在Java中继承哪些方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,我是Java的新手。我试图了解Java中的继承和子类/超类关系。

Sorry I am a newbie to Java. I am trying to get my head around inheritance and subclass/superclass relationships in Java.

如果classA是classB的子类,classA的协议将使用属于classA的所有方法或只是那些宣布公开和包装?

If classA is a subclass of classB, will classA's protocol feature all methods that belong to classA or only those declared public and package?

classA的协议是否可以从其超类ClassB继承私有方法?

Can classA's protocol feature private methods inherited from its superclass ClassB?

推荐答案

<首先,继承这个词并不是一个正确的术语。你的意思是可见的。

Firstly, the word "inherited" isn't quite the right term. You mean "visible".


  • public protected 始终可见

  • 私人不可见

  • 默认(也就是包)可见性 - 即没有指定的可见性 - 只有当子类在同一个包中时才可见(就像在同一个包中的任何类一样)

  • public and protected are always visible
  • private is not visible
  • default (a.k.a. "package") visibility - ie no specified visibility - is visible only if the subclass is in the same package (as it be would for any class in the same package)

这篇关于子类可以在Java中继承哪些方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆