java - The interface code is giving compile time error -


interface i1 {     int = 10;     void add();     void sub();     void del(); } interface i2 {     void disp(); } class implements i1,i2 {     void add(){...}     void sub(){...}     void del(){...}     void disp(){         system.out.println(i);     } }  

this code giving compile time error. don't know wrong code.

implicitly, i1.add() et al public. therefore in class must make them public:

public void add(){...} public void sub(){...} public void del(){...} public void disp(){     system.out.printf(i); } 

otherwise you'd get

cannot reduce visibility of inherited method test.i1 

also, call printf() needs change to:

system.out.printf("%d", i); 

(the first argument format string.)


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -