Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does run() method is declard i Thread?

 
Maciej Zpolski
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maciej,
In my opinion start() is only defined in Thread class.run() is a part of Runnable interface.
 
Henry Wong
author
Marshal
Pie
Posts: 21413
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Maciej Zpolski
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic