这个问题也涉及同样的问题,但我不明白,这如何造成(似乎)矛盾的情况。
Says说,“子阶级不继承母阶级的私人成员”。
这意味着它既不继承私人情况变数,也不继承私人方法权?
然而,如果它从父母那里继承一种公共使用方法,这项工作如何? 它回到了一种情况变数,它不知道有吗?
此外,我的计算机科学书籍(Baron s AP Computer Science A)对一个问题有正确答案,即“(子)从(Superster)”继承所有私人案例变量和公共查阅方法。
是否在收缩或理论?
感谢您的帮助
这个问题也涉及同样的问题,但我不明白,这如何造成(似乎)矛盾的情况。
Says说,“子阶级不继承母阶级的私人成员”。
这意味着它既不继承私人情况变数,也不继承私人方法权?
然而,如果它从父母那里继承一种公共使用方法,这项工作如何? 它回到了一种情况变数,它不知道有吗?
此外,我的计算机科学书籍(Baron s AP Computer Science A)对一个问题有正确答案,即“(子)从(Superster)”继承所有私人案例变量和公共查阅方法。
是否在收缩或理论?
感谢您的帮助
私人成员也继承。 为了测试这一点,你可以在超级舱内做以下工作:
//...
private String myText = "I m in the superclass";
private void setMyText(String myTextValue)
{
this.myText = myTextValue;
}
public void setMyTextPublic(String myTextValue)
{
setMyText(myTextValue);
}
public String getMyText()
{
return myText;
}
//...
在继承类别中创造一种方法:
//...
public void setMyTextInTheSuperClass(String myTextValue)
{
System.out.println(getMyText());
setMyTextPublic(myTextValue);
System.out.println(getMyText());
}
public void setConstantValueToMyText()
{
setMyTextInTheSuperClass("I am in the child class");
}
//...
And calls setConstantValue ToMyText some where.
进入者将罚款。 认定进入者在超级阶级的“文字”中操作,因此,进入者将能够看到该成员隐藏在子类中。
至于教科书,这取决于你的观点。 该子公司继承私人成员,其意思是,他们实际上在子类别内(因此,他们拿着记忆等),但下级无法直接接触他们。
想像.。 各级等级都是一层。 例如,如果C级延伸B级,则C类的物体为:
https://i.stack.imgur.com/q1TLY.png”rel=“noreferer”>Object of par C
-------------------------------------------------------------
| |
| C and it s members |
| |
| ------------------------------------------------ |
| | | |
| | B and it s members | |
| | ------------------------------------ | |
| | | A and it s members | | |
| | | | | |
| | ------------------------------------ | |
| ------------------------------------------------ |
| |
-------------------------------------------------------------
So, an object of class C does have members of B and A. But it cannot access private members of B and A.
然而,它可以接触B和A的公众和保护成员。
因此,B类或A类的公用配件功能允许C类的该物体进入B类或A类“part<的私人试样。
这里的“继承”是指你不能获得。 仍然存在,绝非是你可以与你进行互动(但要求超级阶级的非私人方法除外)。
The accepted answer in the question you linked to does explain that. Is there anything particular part of that explanation that isn t clear?
Certainly when you create an object of a class B
that inherits from a class A
if the class A
has private items, according to the rules of access in Java, you can not have access them, but these elements do exist in private memory, even as null references if they were null objects.
可在《 Java语言规格<>上读:
A class inherits from its direct superclass and direct superinterfaces all the nonprivate fields of the superclass and superinterfaces that are both accessible to code in the class and not hidden by a declaration in the class.
A
private
field of a superclass might be accessible to a subclass - for example, if both classes are members of the same class. Nevertheless, aprivate
field is never inherited by a subclass.
如果子类是同一包裹,它继承私人成员,否则它只继承公共和受保护的成员!
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...