• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does run() method is declard i Thread?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maciej,
In my opinion start() is only defined in Thread class.run() is a part of Runnable interface.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)?
 
reply
    Bookmark Topic Watch Topic
  • New Topic