permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Does run() method is declard i Thread? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Does run() method is declard i Thread?" Watch "Does run() method is declard i Thread?" New topic
Author

Does run() method is declard i Thread?

Maciej Zpolski
Greenhorn

Joined: Nov 02, 2006
Posts: 10
Hi,
There is a question in MasterExam:
Which of the fallowing methods are defined in the Thread class?
Answer is: run() and start()

But Thread implements Runnable, which declares method run().
Does it mean, that when a class implements an interface, it defined method from that interface, but when it extends other class and overrides or not method from that class it don't defined that methods?


Sorry for my english..
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
Maciej,
In my opinion start() is only defined in Thread class.run() is a part of Runnable interface.


~Sanjeev Singh<br />SCJP 1.5
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18532
    
  40

Originally posted by Maciej Zpolski:
But Thread implements Runnable, which declares method run().
Does it mean, that when a class implements an interface, it defined method from that interface, but when it extends other class and overrides or not method from that class it don't defined that methods?


I am not completely sure what you are asking... but if I assume correctly...

No. If a class implements an interface, it doesn't have to provide the implementations for the interface. The implementation may be from a class that it inherits from, or the class may be abstract.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Maciej Zpolski
Greenhorn

Joined: Nov 02, 2006
Posts: 10
I try in different way

interface A{
void method1();
}

class B{
void method2(){}
void method3(){}
}

class C extends B implements A{
public void method1(){}
void method2(){}
}

Which of fallowing methods are defined in class C?
1) method1()
2) method2()
3) method3()

I think that 1) and 2), because they are given explicity in C. Am I right?
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
No,I disagree It is the interface A and class B which gave birth to these methods.Class C is only taking the legacy from their parents.
Maciej Zpolski
Greenhorn

Joined: Nov 02, 2006
Posts: 10
Comparing to MasterExam answer for question about Thread:
1) is correst (run() is defined in Thread)
3) is incorrect (wait() isn't defined in Thread)

But what about 2)?
 
Consider Paul's rocket mass heater.
 
subject: Does run() method is declard i Thread?
 
Similar Threads
Which are thread instance methods?
run()
A Question for beginners - 2
Marcus Exam
Doubt in Thread run method.