wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question: ePractice Exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question: ePractice Exam" Watch "Question: ePractice Exam" New topic
Author

Question: ePractice Exam

sukhy johal
Greenhorn

Joined: Jun 14, 2002
Posts: 2
Hi,
I've been going through the Sun ePractice exams and had one question.
I don't understand why the following code would work without extending the Thread class - any ideas?
Thanks
1. public class Snow {
2. public static void main(String [] args) {
3. Snow s = new Snow();
4. new Thread() {
5. public void run() {
6. for (int w = 0; w < 2; w++) {
7. System.out.print(w);
8. }
9. }
10. }.start();
11. new Thread() {
12. public void run() {
13. for (int z = 5; z < 7; z++) {
14. System.out.print(z);
15. }
16. }
17. }.start();
18. }
19. }
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
sukiuk,
Welcome to Javaranch
We'd like you to read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you.
Corey


SCJP Tipline, etc.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by sukiuk:
I don't understand why the following code would work without extending the Thread class - any ideas?

There is a special syntax being used here. Look at the following code:

This code creates an anonymous class that does extend Thread. That is accomplished by stating "new Thread() { ... }". You can find more about this in the JLS, §15.9.5 Anonymous Class Declarations.
I hope that helps,
Corey
sukhy johal
Greenhorn

Joined: Jun 14, 2002
Posts: 2
Thankyou Corey - I "get" it now.
Sukhy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question: ePractice Exam
 
Similar Threads
Hi Thread doubt
Another Thread Question
problems in threads(sun accesibility test)
Threads
Thread Program