Page 1 of 1

Test 4, #63, program does not compile

Posted: Sun Aug 11, 2013 1:33 pm
by dserge01
Question 63 of Test 4 says:
What will be the output of compiling and running the following program:
class TestClass implements I1, I2{
public void m1() { System.out.println("Hello"); }
public void m2() { System.out.println("Hello2"); }
public static void main(String[] args) {
TestClass tc = new TestClass();
( (I1) tc).m1();
}
}

interface I1{
int VALUE=1;
void m1();
}

interface I2{
int VALUE=2;
void m2();
}

The program failed to compile and said: "TestClass.java:1: error: TestClass is not abstract and does not override abstract method m2() in I2
class TestClass implements I1, I2{
^
1 error"
That would mean the answer to the question is D and not A.
By the way, if I add "public void m2() { System.out.println("Hello2"); }" immediately after "public void m1() { System.out.println("Hello"); }", the output would be "Hello"
Dmitry Sergeev

Re: Test 4, #63, program does not compile

Posted: Mon Aug 12, 2013 7:38 am
by admin
Are you sure you are trying the code exactly as given? I just tried it and it compiles fine. Btw, if you click the "Discuss" button on the question view, you will be taken to an existing thread on that question (if it exists). This question has already been discussed here.

HTH,
Paul.