简体   繁体   中英

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. The application for the windows is created by Oracle Press (probably). 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:

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. A and B are incorrect. 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 . 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM