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
Test 4, #63, program does not compile
Moderator: admin
-
- Posts: 2
- Joined: Thu Aug 08, 2013 6:45 pm
- Contact:
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: Test 4, #63, program does not compile
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 30 guests