Important Java Mcq 1

A method within a class is only accessible by classes that are defined within the same package.

a. Declare the method with the keyword public.

b. Declare the method with the keyword private.

c. Declare the method with the keyword protected.

d. Do not declare the method with any accessibility modifiers.

Answer:

d. Do not declare the method with any accessibility modifiers.

Explanation:

Methods should not be defined with any access modifiers. If you don’t specify an access modifier, it will have default access package-level access if the access modifier is not specified. Members defined in interface type are public by default.

Related MCQs
Aniket Malik

Aniket Malik

CERTIFIED TUTOR/TRAINER WITH 300+ REVIEWS

Facing difficulty with

this concept?