1
1
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?
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?
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.
E). Declare the method with the keyword public and private.
This Question has 1 answers.
Do not declare the method with any accessibility modifiers.
- In Java, if a method is declared without any access modifier, it has package-private (default) access.
- This means the method is accessible only within the same package but not from outside the package, even by subclasses.
- Other options:
A) public → Accessible from anywhere.
B) private → Accessible only within the same class.
C) protected → Accessible within the same package and subclasses.
E) public and private → This is not possible in Java.
Similar Questions
- In an alloy, zinc and copper are in the ratio 1 : 2. In the second alloy, the same elements are in the ratio 2 : 3. If these two alloys be mixed to form a new alloy in which two elements are in the ratio 5:8, the ratio of these two alloys in the new allow
- Directions: In a family of eight members, there are two married couples and a widow. B, an engineer is married to a doctor. D, an architect is the wife of C. F, a student is the only child of D. H is the son of G and his sister E is the niece of the manag
- Directions: In a family of eight members, there are two married couples and a widow. B, an engineer is married to a doctor. D, an architect is the wife of C. F, a student is the only child of D. H is the son of G and his sister E is the niece of the manag
- Nidhi received simple interest off Rs. 1200 when invested Rs x at 6% p.a. and Rs y at 5% p.a. for 1 year. Had she invested Rs. x at 3% p.a. and Rs. y at 8% for that year, she would have received simple interest of Rs 1,260. Find the values Rs. x an y.
- The letters A, B, C, D, E, F and G not necessarily in that order, stand for seven consecutive integers from 1 to 10, D is 3 less than A, B is the middle term. F is as much less than B as C is greater than D, G is greater than F.