avatar
关于Protected变量# Java - 爪哇娇娃
p*p
1
涵义当然明白,只有本package才能使用,请问在
编程上代表一种什么意图,实现什么想法时候用
public当然好理解,private也是,只有通过get
set才能使用,作者可以控制。
avatar
w*r
2
let's say you have a abstract class and it will be inherited by
some other classes in the same package, here is a abstract function that
all extended class should have to make it work .As you can read from the
following example, all vehicles should have mechanism to speedup and slow
down , however, speedup and slowdown are two "internal" mechanisms, which
each type of vehicle may carry differnet public function to trigger speedup
or slowdown, such as applyMoreGas() for car, peddleFaster() for bi

【在 p***p 的大作中提到】
: 涵义当然明白,只有本package才能使用,请问在
: 编程上代表一种什么意图,实现什么想法时候用
: public当然好理解,private也是,只有通过get
: set才能使用,作者可以控制。

avatar
b*l
3
这个看看design pattern 会有比较直观的应用理解。

【在 p***p 的大作中提到】
: 涵义当然明白,只有本package才能使用,请问在
: 编程上代表一种什么意图,实现什么想法时候用
: public当然好理解,private也是,只有通过get
: set才能使用,作者可以控制。

avatar
g*g
4
No, protected is mainly for visiblity in subclasses, although it's also
visible in the same package.
For visibility in the same package only, use default or no descriptor.
If you are developing an API package, there is a huge difference between
default and protected restriction. Default or private is internal to the
package and thus can be easily changed later on. protected and public are
exposed signature and "committed" to outside world. They need careful design
and any later change may be co

【在 p***p 的大作中提到】
: 涵义当然明白,只有本package才能使用,请问在
: 编程上代表一种什么意图,实现什么想法时候用
: public当然好理解,private也是,只有通过get
: set才能使用,作者可以控制。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。