• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Threads Doubt

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given:


Answer: B

I guessed the answer as B and it is correct, but I don't know the reasoning behind it.

Can anyone please explain ?
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
the first method:

public void run() {
System.out.print(�Cat�);
}

has been hide by the second method :

public void run() {
System.out.print(�Dog�);}
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public void run()
{
System.out.print("Dog');
}

This method overrides the run() method defined in the Thread class, so "t.start()" normally calls the run() method of Thread will forwards the call to run() method of Runnable.

However, due to this overridding run() method will not be called from Thread so no call is forwarded to Runnable's run() method.
Instead the overriding run() method is called. That is why answer is - "Dog".
 
Grow a forest with seedballs and this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic