+ 11
challenge question
What is the output of this code? interface P { void print(int x); } class Main implements P { void print(int x) { System.out.print(x); } public static void main(String...arg) { P ob = new Main(); ob.print(10); } } I didn't understand what is the error
2 Answers
+ 4
"All abstract, default, and static methods in an interface are implicitly public, so you can omit the public modifier." [in interface]
class Main implements P {
public void print(int x) { //added public
if you implement print without public, you change public method to non public.
it causes error.
+ 6
đ„đđđ
thank you