• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Exam Qn format

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Here is a question from the Sun sample test for SCJP 1.4

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. }


What is the result?

Since the above code starts on line 1 I immediately thought there would be a compilation error because the main method isn't in a class.

However, the answer is a compilation error but in the answer the reason they give is because the class T3 doesn't implement the java.lan.Runnable interface properly.

Should I have just assumed that this method was in a class?

Thanks
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Should I have just assumed that this method was in a class?



A java method can't exist alone unlike C language. So obivously there is no pointing asking about that.

If you see the choices, you can easily figure out those problems which looks like little incomplete.

Th only problem in above code is due to not overriding of run() method in class T3

Naseem
[ August 08, 2006: Message edited by: Naseem Khan ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic