Declaration And Access Control - Study Mode

[#11] Suppose a class has public visibility. In this class we define a protected method. Which of the following statements is correct?
Correct Answer

(D) This method is accessible from within the class itself and from within all classes defined in the same package as the class itself.

[#12] The object is created with new keyword
Correct Answer

(B) At run-time

[#13] A package is a collection of
Correct Answer

(D) Classes and Interfaces

Explanation

Solution: Think of a package like a folder or a directory on your computer. What do you usually put in a folder? Files! In Java, packages help us organize our code. Classes and Interfaces are both types of "files" in Java. So, a package can contain both. Option A is partially correct (Classes), but it's not the whole story. Option B is also partially correct (Interfaces), but it's also not the complete picture. Option C and Option E are incorrect because "Editing tools" are not stored within the Java package. Option D is the most accurate. Therefore, the correct answer is D: Classes and Interfaces.

[#14] A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction?
Correct Answer

(D) Do not declare the method with any accessibility modifiers.

[#15] Choose the correct statement. Restriction on static methods are: I.xa0xa0xa0They can only call other static methods. II.xa0xa0 They must only access static data. III.xa0They cannot refer this or super in any way.
Correct Answer

Only (I)