1.10. Answers to sample exam questions
Given:
class EJava { //..code }Which of the following options will compile?
package java.oca.associate; class Guru { EJava eJava = new EJava(); } package java.oca; import EJava; class Guru { EJava eJava; } package java.oca.*; import java.default.*; class Guru { EJava eJava; } package java.oca.associate; import default.*; class Guru { default.EJava eJava; }- None of the above
Answer: e
Explanation: A class that isn’t defined in a package gets implicitly defined in Java’s default package. But such classes can’t be accessed by classes or interfaces, which are explicitly defined in a package.
Option a is incorrect. The EJava class isn’t defined in a package, so it can’t be accessed ...
Get OCA Java SE 8 Programmer I Certification Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.