Home > Archive > Java Help > April 2004 > studying for SCJP1.4 and have a question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
studying for SCJP1.4 and have a question
|
|
|
| Ok, I don't get this. I'm using the mock test from Sun and here's the
question:
Given:
1. public static void main( String[] args ) {
2. class T1 extends java.lang.Thread{}
3. class T2 extends T1{}
4. class T3 implements java.lang.Runnable{}
5.
6. new T1().start();
7. new T2().start();
8. new Thread(new T3()).start();
9. System.out.println( "Executing" );
10. }
Here's the multiple choice answers:
A - Compilation fails.
B - The program never terminates.
C - The program runs with no output.
D - An exception is thrown at runtime.
E - The program outputs Executing and then terminates.
F - The program terminates after the third thread is created.
The correct answer according to the test reference is:
Option A. Compilation failure, T3 does not implement the interface Runnable
and is therefore abstract and cannot be instantiated
I don't understand that answer. Doesn't T3 implement the Runnable interface
in line 4??? Where am I going wrong with my reasoning?
Thanks,
Axl
| |
| Peter Kirk 2004-04-22, 11:37 am |
| "Axl" <axlstowe@nospamhere.com> skrev i en meddelelse
news:108flrclt497d4b@corp.supernews.com...
<snip>
> 4. class T3 implements java.lang.Runnable{}
<snip>
> I don't understand that answer. Doesn't T3 implement the Runnable
interface
> in line 4??? Where am I going wrong with my reasoning?
Well, it says it implements the interface, but if so then it needs to
implement the methods defined in that interface (or declare itself
abstract). And it does not do that.
| |
| Doug Schwartz 2004-04-27, 4:12 am |
| Runnable has one method, run (the signature is "void run()"). Since T3 did
not implement run, the class cannot compile.
doug
"Peter Kirk" <peter> wrote in message news:4087d9cd$1@news.wineasy.se...
> "Axl" <axlstowe@nospamhere.com> skrev i en meddelelse
> news:108flrclt497d4b@corp.supernews.com...
> <snip>
>
>
> <snip>
>
> interface
>
> Well, it says it implements the interface, but if so then it needs to
> implement the methods defined in that interface (or declare itself
> abstract). And it does not do that.
>
| |
|
| Xref: kermit comp.lang.java.help:174830
T3 does not define the method "public void run(){}" as required by the
Runnable interface.
Line 8, for instance, depends on that run method -which is missing.
~S~
Axl wrote:
> Ok, I don't get this. I'm using the mock test from Sun and here's the
> question:
>
> Given:
>
> 1. public static void main( String[] args ) {
> 2. class T1 extends java.lang.Thread{}
> 3. class T2 extends T1{}
> 4. class T3 implements java.lang.Runnable{}
> 5.
> 6. new T1().start();
> 7. new T2().start();
> 8. new Thread(new T3()).start();
> 9. System.out.println( "Executing" );
> 10. }
>
>
> Here's the multiple choice answers:
>
> A - Compilation fails.
> B - The program never terminates.
> C - The program runs with no output.
> D - An exception is thrown at runtime.
> E - The program outputs Executing and then terminates.
> F - The program terminates after the third thread is created.
>
> The correct answer according to the test reference is:
> Option A. Compilation failure, T3 does not implement the interface Runnable
> and is therefore abstract and cannot be instantiated
>
> I don't understand that answer. Doesn't T3 implement the Runnable interface
> in line 4??? Where am I going wrong with my reasoning?
>
> Thanks,
> Axl
>
>
|
|
|
|
|