1Z0-803 · Question #240
Given: package p1; public interface DoInterface { void method1(int n1); // line n1 } package p3; import p1.DoInterface; public class DoClass implements DoInterface { public DoClass(int p1) { } public
The correct answer is C. Changing the private modifier on the declaration of method 2 public at line n3. Private members (both fields and methods) are only accessible inside the class they are declared or inside inner classes. private keyword is one of four access modifier provided by Java and its a most restrictive among all four e.g. public, default(package), protected and private
Question
Given:
package p1; public interface DoInterface { void method1(int n1); // line n1 } package p3; import p1.DoInterface; public class DoClass implements DoInterface { public DoClass(int p1) { } public void method1(int p1) { } // line n2 private void method2(int p1) { } // line n3 } public class Test { public static void main(String[] args) { DoInterface doi= new DoClass(100); // line n4 doi.method1(100); doi.method2(100); } } Which change will enable the code to compile?
Options
- AAdding the public modifier to the declaration of method1 at line n1
- BRemoving the public modifier from the definition of method1 at line n2
- CChanging the private modifier on the declaration of method 2 public at line n3
- DChanging the line n4 DoClass doi = new DoClass ( );
How the community answered
(50 responses)- A8% (4)
- B12% (6)
- C50% (25)
- D30% (15)
Explanation
Private members (both fields and methods) are only accessible inside the class they are declared or inside inner classes. private keyword is one of four access modifier provided by Java and its a most restrictive among all four e.g. public, default(package), protected and private. always.html#ixzz3Sh3mOc4D
Topics
Community Discussion
No community discussion yet for this question.