• 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
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Question on Constructors

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In regard to constructors, how can you prevent a class from being instantiated?
A. Use the private declaration.
B. Use anonymous classes.
C. Employ overloading.
D. Use only static inner classes.
the answer is given as A, why can't be B.
Thanks in Advance.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is A coz you if you use anonymous classes only you can instantiate it & use it in the class you defined etc. (note you can still instantiate it.) secondly its not a top level class all questions should be assumed as top level class question until specified otherwise(As per my experience in all mock exams)
Again to explain in detail say if you take the static class example java.lang.Math class you can't make a instance of this class as the constructor is private.
Its a normal practice to create such classes for Util methods.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic