java - How interface support multiple inheritance -
this question has answer here:
- multiple inheritance on java interfaces 5 answers
public class test implements x, y { //x.y interface shown below public void mymethod() { system.out.println(" multiple inheritance example using interfaces"); } public static void main(string[]args) { test t=new test(); t.mymethod(); system.out.println(t.a); //compile time error ambigious field } }
please me solve issue
interface x { public void mymethod(); int = 0; } interface y { int = 9; public void mymethod(); }
any variable defined in interface is, definition, public static final
, in other words it's constant, it's not field (since there no fields in interfaces).
so compilation error points out compiler doesn't know witch constant refer to.
you have 2 options here:
change name of constant in 1 of interfaces, example in
interface y
declareint b = 9;
inside
main
method point concrete constant:system.out.println(x.a);
Comments
Post a Comment