Hello again, another question today...

Based on this example :

public interface A {

   public boolean booleanA = true;
   public boolean booleanB = true;
   public boolean booleanC = true;
}

public interface B implements A {
   public boolean booleanA = false;
}

public class Example implements B {

public Example() {}
}

What are the values of booleanA, booleanB and booleanC in class Example?

I'd say (FALSE, TRUE, TRUE)... but I'm not sure.
Anyone able to clarify?

I believe that would be correct. Since B get everything from A, and then changes booleanA. So when example gets everything from B it will have the values: False, true, true.

Nothing. Or, you will not see anything. But the computer is going to make an instance of "example" and then terminate, since nothing is happening (the code does not do anything). This is of course if you instantiate the class example, and add the necessary code for the program to actually be able to run. Right now it will not do anything, except maybe crash. There is no main method for instance.

Or did you mean in general what happens when you compile and run?

Edited 6 Years Ago by Cort3z: n/a

I get an error when trying to compile it:

TestInterface.java:9: '{' expected
interface B implements A {

So, let me tell you what I found out...

public interface A {
   boolean a1 = false;
   boolean a2 = false;
}
public interface B extends A {
   boolean a1 = true;
}
public class C implements B {
   public void printBoolean() {
      System.out.print(a1);
      System.out.print(a2);
   }
}

On the code above I get the following error on Eclipse :

a1 is ambiguous. (line 10)
and it won't let me run the program.

I have not tested anything else than boolean data type, but as far as boolean is concerned, this thing above won't work.

For one thing you changed implements to extends. That was what my compile complained about.
The OP obviously didn't try compiling it.

Edited 6 Years Ago by NormR1: n/a

An honest mistake ;).
Only classes IMPLEMENT interfaces...
Interfaces can only extend other interfaces, never implement

This article has been dead for over six months. Start a new discussion instead.