Topic: 概念问题,类的继承和访问

  Print this page

1.概念问题,类的继承和访问 Copy to clipboard
Posted by: truthawp
Posted on: 2005-08-09 20:24

有这样两道题1.子类能继承父类的所有方法和状态(正确)2.类的私有方法不能被其子类直接访问(正确)
书上说这两题都是正确的,但是这样不是矛盾了么? 难道继承!=访问?那到底是什么概念呢?
还有1里的状态指的是什么?是成员变量么?Stupid

2.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-08-09 21:13

1.子类能继承父类的所有方法和状态 WRONG!!!!

2.类的私有方法不能被其子类直接访问(正确) INACCURATE!!!

What kind of book this is???
Throw it into GC!

Thanks!

Read The Java Tutorial

3.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: truthawp
Posted on: 2005-08-09 23:26

谢谢斑竹,我粗略的看了下,里面有这样一段:
A subclass inherits all the member variables and methods from its superclass. However, the subclass might not have access to an inherited member variable or method. For example, a subclass cannot access a private member inherited from its superclass.
这样看来似乎有点奇怪,说子类能继承父类所有的成员变量和方法,但是子类不能访问一个已经被继承的成员变量或方法.Java不是不支持多重继承的么?怎么子类会不能访问一个已经被继承的成员变量或方法呢?(已经被继承?多重继承?Stupid)最后说,例如,一个子类不能访问一个已被其父类继承的私有成员???Stupid什么意思?
可能是自己E文不太好,理解上有问题,还请指点一下Embaressed

4.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-08-10 10:02

truthawp wrote:
A subclass inherits all the member variables and methods from its superclass. However, the subclass might not have access to an inherited member variable or method. For example, a subclass cannot access a private member inherited from its superclass.


Sorry, I did not read this paragraph carefully, and now I see. According to this paragraph, the original questions and answers are correct, if we take the "直接"away.

1.子类能继承父类的所有方法和状态(正确)
2.类的私有方法不能!!take 直接 away!!被其子类访问(正确)

My apologies! Embaressed

To truthawp
1) This is a definition problems, inherited but no access is equivalent to not inherited to me. However, if Sun said so, then we say the same... Smile

2) This has nothing to do with 多重继承, don't make things more complicated than it ought to be!

Thanks!

5.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: truthawp
Posted on: 2005-08-10 12:01

呵呵 一开始我也是这么想的,不能访问,那还继承了干吗? Confused
因为能从Sun那里找的到原句,那两道定义就对吗?Stupid 我觉得可能还是有点问题,原文如下:
A subclass inherits all the member variables and methods from its superclass. However, the subclass might not have access to an inherited member variable or method. For example, a subclass cannot access a private member inherited from its superclass. One might say, then, that the item was not inherited at all. But the item is inherited. This becomes important when using an inner class, which does have access to its enclosing class's private members. Note that constructors are not members and so are not inherited by subclasses.
还请各位前辈帮忙解释下~Smile( 因为是初学,所以原版英语单词和现在书上的名词不一定对的准确)
(怎么感觉象在做英语阅读?Embaressed) Big Smile

6.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: truthawp
Posted on: 2005-08-10 20:18

我只想知道上面的item和constructor对应的是我们中文里所用的什么术语?(哪个名词)Smile

7.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-08-10 22:26

If you start not to ask "中文里所用的什么术语", then your Java and English will become better and better.

Just a suggestion, it is up to you! Smile

8.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: truthawp
Posted on: 2005-08-11 00:04

thx,I think I'll try my best in both Java and English~Smile

9.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: yoreland
Posted on: 2005-08-14 10:00

truthawp wrote:
我只想知道上面的item和constructor对应的是我们中文里所用的什么术语?(哪个名词)Smile


constructor是构造函数
至于item我想是成员的意思吧

10.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: mastersky
Posted on: 2005-09-28 23:54

子类继承了超类的方法和状态,但是不能访问超类的一些方法和状态。比如私有变量。继承了也需要通过protected或public方法和状态来访问它们。就是说在内存里分配了地址给它们,但是不能直接访问它们。但是构造函数不属于类的成员,所以不能被继承。我想大致是这个意思吧。

11.Re:概念问题,类的继承和访问 [Re: truthawp] Copy to clipboard
Posted by: 华清
Posted on: 2005-10-01 09:33

Thinking in English


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923