Test 4, #63, program does not compile

Moderator: admin

Post Reply
Posts: 2
Joined: Thu Aug 08, 2013 6:45 pm

Test 4, #63, program does not compile

Post by dserge01 » 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

Site Admin
Posts: 8351
Joined: Fri Sep 10, 2010 9:26 pm

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

Post by admin » Mon Aug 12, 2013 7:38 am

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.

If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests