+ 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

8th Sep 2019, 8:18 PM
ABADA S
ABADA S - avatar
2 odpowiedzi
+ 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.
8th Sep 2019, 8:47 PM
zemiak
+ 6
🔥👏👏👏 thank you
8th Sep 2019, 8:49 PM
ABADA S
ABADA S - avatar