Results 1 to 2 of 2

Thread: instantiation

  1. #1
    Camden is offline Member
    Join Date
    Nov 2007
    Posts
    13
    Rep Power
    0

    Default instantiation

    :confused: Write a class, which can be instantiated at most 100 times.
    If an attempt is made to instantiate it after 100 instances have been created, the constructor should throw an exception. It should also have a toString method which returns the position of the object in the sequence of instantiations.

    how can we set the limit 100?
    what is the 'position of the object in the sequence of instantiations'?

    any idea?

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    Make the default constructor private! and create a static method named createObject() which returns the object created. Inside this method, you can write an if sentence to limit number of objects created..

Similar Threads

  1. Instantiation using an instance factory method
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-29-2008, 12:35 PM
  2. Instantiation
    By kavithas in forum New To Java
    Replies: 2
    Last Post: 12-05-2007, 04:56 PM
  3. Instantiation using an instance factory method
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 08:25 PM
  4. object instantiation and arrayList
    By lockmac in forum New To Java
    Replies: 5
    Last Post: 08-09-2007, 06:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •