• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

jtips

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How does the follo prints false?
class Process
{
Process()
{
write();
}
void write()
{
System.out.println(Thread.activeCount());
}
}
class Test extends Process
{
public static void main(String[] args)
{
Process t = new Test();
}
public void write()
{
System.out.println(Thread.interrupted());
}
}
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what I found.
It has everthing to do with the modifier of the parent class.
In this instance the modifier for write() in super class is default.
At run time, the object refers to the sub class and therefore when write method is called within the constrcutor, the write method of the object it belongs to(sub class) is called, in this case being Thread.isInterrupted which returns false.
Note: If you change the super class write method to be private then, guess what... the Thread.activeThreadCount will be called.
It has to do with method being bound at compile time, private methods are bound but not public, default and protected.( I am not 100% sure about this)
This was a good question.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic