AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

studying for SCJP1.4 and have a question

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Axl
Guest





PostPosted: Thu Apr 22, 2004 2:32 pm    Post subject: studying for SCJP1.4 and have a question Reply with quote



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


Back to top
Peter Kirk
Guest





PostPosted: Thu Apr 22, 2004 2:42 pm    Post subject: Re: studying for SCJP1.4 and have a question Reply with quote



"Axl" <axlstowe (AT) nospamhere (DOT) com> skrev i en meddelelse
news:108flrclt497d4b (AT) corp (DOT) supernews.com...
<snip>

Quote:
4. class T3 implements java.lang.Runnable{}

<snip>

Quote:
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.


Back to top
Doug Schwartz
Guest





PostPosted: Tue Apr 27, 2004 3:52 am    Post subject: Re: studying for SCJP1.4 and have a question Reply with quote



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

Quote:
"Axl" <axlstowe (AT) nospamhere (DOT) com> skrev i en meddelelse
news:108flrclt497d4b (AT) corp (DOT) 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.




Back to top
xaos
Guest





PostPosted: Tue Apr 27, 2004 1:57 pm    Post subject: Re: studying for SCJP1.4 and have a question Reply with quote

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:
Quote:
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




Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.