这里可以继承吗?内部父类是否扩展外部子类?
A
|_A1
| |_parent.java
|_child.java
Parent.java 是否以任何可能的方式继承 child.java ?
这里 A 和 A1 是包或目录
A
|_A1
| |_parent.java
|_child.java
does parent.java inherits child.java in any possible way?
here A and A1 are packages or directories
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅当 Child 具有
extends
子句时如果是这样,
Child
将有权访问public
和protected
的所有成员代码>父级。否则,Child
将只能访问Parent
的public
成员。如果文件位于同一目录层次结构内,但不在同一目录内,则包不被视为相关,因此具有默认(“包保护”)可见性的成员不可见。
相关阅读:
Only if Child has an
extends
clauseIf so,
Child
will have access to allpublic
andprotected
members ofParent
. Otherwise,Child
will only have access topublic
members ofParent
.If files are inside the same directory hierarchy, but not within the same directory, the packages are not considered related, and hence members with default ("package-protected") visibility are not visible.
Relevant reading:
您的图片显示了文件夹和 java 源文件。我们有一个文件夹
A
,其中包含文件child.java
和另一个文件夹A1
。A1
包含 java 源文件parent.java
。在文件系统文件夹中排列源文件(或类文件)不会创建或声明类之间的关系。
如果您希望类
parent
继承类child
(iaw:parent
继承child
的字段和方法- 在现实世界中很奇怪但可能),你必须在java源代码中声明这种关系。保留您的名称,文件必须如下所示:child.java
parent.java
注意 - java 命名约定强烈建议,即包名称都是小写字母,类名以大写字母开头。
Your picture shows folders and java source files. We have one folder
A
that contains the filechild.java
and another folderA1
.A1
contains the java source fileparent.java
.Arranging source files (or class file) in filesystem folers does not create or declare relationships between classes.
If you want class
parent
to inherit (from) classchild
(iaw:parent
inherits fields and method fromchild
- strange in real world but possible), you have to declare this relation in the java source code. Keeping your names, the files have to look like this:child.java
parent.java
Note - java naming conventions strongly recommend, that package names are all lower case and class names start with a capital letter.
否
我的理解是,这是你的包/树层次结构,并且你要求任何继承。
如果有任何继承,它看起来像任何继承/树层次结构吗?如果您破坏继承树,则意味着在任何其他不相关的包或任何其他节点下不应该有任何继承的类。换句话说,缺乏设计模式。如果这样做,您将处理包级别以及与其他包的冗余可访问性,因此您不能谈论此项目中的 OO 或任何封装
NO
What I understood is that it is your package/tree hierarchy and you asked for any inheritance.
If there is any inheritance, does it look like any inheritance/tree hierarchy? If you destroy the inheritance tree it means there shouldn't be any inherited class under any other irrelevant package or under any other node. In other words, lack of design pattern. If you do this, you will handle the redundant accesibility in package-level and with other packages and so you can't talk anything about OO or any encapsulation in this project