Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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



Report this thread to moderator Post Follow-up to this message
Old Post
Axl
04-22-04 04:37 PM


Re: studying for SCJP1.4 and have a question
"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.


Report this thread to moderator Post Follow-up to this message
Old Post
Peter Kirk
04-22-04 04:37 PM


Re: studying for SCJP1.4 and have a question
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.
>



Report this thread to moderator Post Follow-up to this message
Old Post
Doug Schwartz
04-27-04 09:12 AM


Re: studying for SCJP1.4 and have a question
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 Runnabl
e
> and is therefore abstract and cannot be instantiated
>
> I don't understand that answer.  Doesn't T3 implement the Runnable interfa
ce
> in line 4???  Where am I going wrong with my reasoning?
>
> Thanks,
> Axl
>
>


Report this thread to moderator Post Follow-up to this message
Old Post
xaos
04-27-04 03:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:57 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.