Test 4, #63, program does not compile
Posted: Sun Aug 11, 2013 1:33 pm
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
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