简体   繁体   English

Oracle Java 7认证:私有和受保护的访问修饰符可以与哪些实体一起使用?

[英]Oracle Java 7 Certification: The private and protected access modifiers can be used with which entities?

I am experimenting the questions from Oracle for the Java 7 Associate certification. 我正在试验来自Oracle的Java 7 Associate认证问题。 The application for the windows is created by Oracle Press (probably). Windows的应用程序由Oracle Press创建(可能)。 They've sent it to me with the Book. 他们已随书寄给我。

Currently, I have one question which application says "wrong answer", when I say that all answers are correct. 当前,当我说所有答案都是正确的时,我有一个问题哪个应用程序说“错误答案”。 Could someone explain this? 有人可以解释一下吗? The question is that Inner classes and inner interfaces can be both private and protected, but the explanation says classes and interfaces can't be. 问题是内部类和内部接口可以是私有的也可以是受保护的,但是解释说类和接口不能是私有的。 Please find question and explanation below. 请在下面找到问题和解释。 I hope this is the right place to ask this kind of questionJ. 我希望这是提出此类问题的正确地方。

Question

The private and protected access modifiers can be used with which entities? (Choose all that apply.)

Answers: 回答:

 A: Classes
 B: Interfaces
 C: Constructors
 D: Methods
 E: Data Members

Correct Answers from Oracle: 来自Oracle的正确答案:

C: Constructors 
D: Methods
E: Data members

EXPLANA TION: C, D, and E. The private and protected access modifiers can be used with constructors, methods, and data members. 解释:C,D和E。private和protected访问修饰符可与构造函数,方法和数据成员一起使用。 A and B are incorrect. A和B不正确。 The private and protected access modifiers cannot be used with classes and interfaces. 私有和受保护的访问修饰符不能与类和接口一起使用。

The question is that Inner classes and inner interfaces can be both private and protected 问题是内部类和内部接口可以是私有的也可以是受保护的

Yes you are right. 是的,你是对的。 But we should treat them as Data Members of that Class which they are presented. 但是我们应该将它们视为所提供的该类的数据成员。 Since they are not individual classes,interfaces we should not say them. 由于它们不是单独的类,所以我们不应该说它们。

Ofcourse in the explanation they must mention the word TOP LEVEL . 当然,在解释中他们必须提到TOP LEVEL这个词。 Absence of that causing the confusion here. 缺少它会引起混乱。

I guess the trick here is that the question doesn't take inner classes and interfaces into account. 我猜这里的窍门是这个问题没有考虑内部类和接口。 Answers A and B only refer to top-level class and interface declarations (although not explicitly stated). 答案A和B仅指顶级类和接口声明(尽管未明确说明)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么类或接口不能接收私有或受保护的访问修饰符? - Why can't a class or an interface receive private or protected access modifiers? 批注或其方法是否可以具有私有,默认或受保护的访问修饰符? - Can annotations or its methods have the access modifiers like private, default or protected? 访问修饰符的安全影响(公共,私有,内部,受保护) - Security impact of access modifiers (public, private, internal, protected) Java 访问修饰符关键字(私有、默认、受保护、公共或最终,static 等)自动隐藏在 eclipse 中,但显示在源文件中 - Java Access Modifiers keyword (private, default, protected, public or final, static etc..) automatically hide in eclipse but show in source file Spring Access修饰符私有 - Spring access modifiers private jsonobject IllegalAccessException无法使用修饰符“private”访问类java.util.HashMap的成员 - jsonobject IllegalAccessException can not access a member of class java.util.HashMap with modifiers “private” 在Java中的私有静态嵌套类中访问修饰符 - Access modifiers inside a private static nested class in Java 无法访问外部类修饰符(java) - can`t access outer class modifiers (java) 用于 Java 中的类的修饰符 - Modifiers used for Classes in Java Java是否具有“私有保护”访问修饰符? - Does Java have a “private protected” access modifier?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM