Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Abhilash -- Questions

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends
Those question are from abhilash's collection.
Q1)A class which has all its constructors declared as private
1)Cannot be instantiated by any other class.
2)Cannot be extended.
3)Both i and ii.
4)has to be declared final.
ans : 3
I think question should be more specific, as one can instantiate such class in inner class defined in this class. What do you say?
Q2)Assume that th is an instance holding a thread object. th.start() causes the thread to start running and eventually complete its execution. The object reference by th is not accessable any more and is garbage collected when the garbage collecter runs.
True
False
ans is false? Do gc work differently in case of Threads ?

Swati
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For question 2, I can read that two ways.


One is stating that th has completed execution and is no longer accessible, so will it be eligble for garbage colletion.


If that is the case then I would say the answer is true.
However, you can also read it this way:


th has completed its excution. Because it has complted execution, it is no longer accessible, so it will be elgible for garbage collection.


I would say false here because just because the run method has completed, doesn't mean that you can no longer access it. You can not make it start() again, but you can still call other methods on it.
Question is a little too ambiguous.
Bill

[This message has been edited by bill bozeman (edited February 28, 2001).]
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am not able to understand why a class with private constructors can not be extended?
please help
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can't be extended because when you extend a class, the subclasses constructors call the construcors of the parent class. It either calls them directly, or it calls the default constructor. If the constructor is private, then it can't call the constructor, hence you can't extend it.
Bill
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there
i'm as green as they come, but i think that if the constructors are private and the methods aren't static then extending the class won't be of much use since u can't use the methods without constructing an instance of the class, but constructors are private.
hope this helps
 
dropinboy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i prefer your answer Bill, the subclass's constructors implicitly call the super classes constructor unless u've explicitely called super();
more of my 2 cents };-)
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dropinboy,
Your name doesn't comply with our naming policy here at the ranch. Check out this link for more info, www.javaranch.com/name.jsp
Please re-register with a more appropriate name.
Thanks,

Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic