can i restrict a class that it will not allows create more than two objects

can i restrict a class that it will not allows create more than two objects

hi all, can i restrict a class that it will not allows create more than two objects can any help me please.
Thaks bala k

View Answers

July 7, 2012 at 12:46 PM

You can restrict a class to make it's "n" number of object , please follow the below mentiond code.

public final class NnumberInstance {

private static NnumberInstance obj[];

private NnumberInstance() {

}

public static NnumberInstance[] getInstance(int n) {
    obj = new NnumberInstance[n];
    for (int i = 0; i < n; i++) {
        obj[i] = new NnumberInstance();
    }
    return obj;

}

}

public static NnumberInstance obj[];

public static void main(String[] args) {

    obj = NnumberInstance.getInstance(5);

    for (NnumberInstance instance : obj) {
        System.out.println("------------------------"+instance.hashCode());
    }

}

}


July 7, 2012 at 12:48 PM

public final class NnumberInstance {

    private static NnumberInstance obj[];

    private NnumberInstance() {

    }

    public static NnumberInstance[] getInstance(int n) {
        obj = new NnumberInstance[n];
        for (int i = 0; i < n; i++) {
            obj[i] = new NnumberInstance();
        }
        return obj;

    }
}

public class MainJavaClass {

public static NnumberInstance obj[];

    public static void main(String[] args) {

        obj = NnumberInstance.getInstance(5);

        for (NnumberInstance instance : obj) {
            System.out.println("------------------------"+instance.hashCode());
        }

    }

}









Related Tutorials/Questions & Answers:
can i restrict a class that it will not allows create more than two objects - Java Interview Questions
can i restrict a class that it will not allows create more than two objects  hi all, can i restrict a class that it will not allows create more than two objects can any help me please. Thaks bala k
Can a Class extend more than one Class?
Can a Class extend more than one Class?   Hi, Can a Class extend more than one Class? thanks
Advertisements
how to restrict user against marking same event more than one times - JSP-Servlet
how to restrict user against marking same event more than one times  Hi I am developing student feedback system for educational institution...(event) is stored in final database. Now how can I restrict the student against
for writting java program why we are taking more than one class
for writting java program why we are taking more than one class  for writting java program only one class is enough but why we are taking more than one class
mapping between java class and more than 2 tables
mapping between java class and more than 2 tables  Association mapping of table in hibernate   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Hibernate Tutorial Thanks
Deployment on Server that can be used simultaneously by more than one user
Deployment on Server that can be used simultaneously by more than one user  Sir, I have deployed my web application developed using JSP & sevlet. how could i access it on the network using xp os. I have deployed it on Tomcat
What can I create with Python?
What can I create with Python?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: What can... that I can learn the topic "What can I create with Python?". Also tell
there are class A & class B.How can i get members of class A& B?
there are class A & class B.How can i get members of class A& B?  there are class A & class B.How can i get members of class A& B
how to create directed line between two buttons when i clicked there
how to create directed line between two buttons when i clicked there  Hi I have to create a topology between 6 nodes. 6 nodes are created as 6 buttons and when i clicked in first button and then on second button a directed
Can you create an object of an abstract class?
Can you create an object of an abstract class?   Hi, Can you create an object of an abstract class? Thanks
how can I great two user and password in C++?
how can I great two user and password in C++?  how can I great two user and password in c
how can I great two user and password in C++?
how can I great two user and password in C++?  how can I great two user and password in C
can i insert values into two tables by a query - JDBC
can i insert values into two tables by a query  hi all, can i insert values into two tables by a query Thanks Bala k
how can i create a discussion forum?
how can i create a discussion forum?  how can i create a discussion forum for my e- mentoring site for women which can be used by a registered user only. i am using jsp and servlets and i am working with netbeans 6.8.
How can I create sessionfactory in Hibernate?
How can I create sessionfactory in Hibernate?  HELLO, How can I create sessionfactory in Hibernate? If you can explain me with example that would... with the links below: Hibernate 4 Hibernate Session Factory I hope
Is Python more powerful than C++?
: Is Python more powerful than C++? Try to provide me good examples or tutorials links so that I can learn the topic "Is Python more powerful than C++?"...Is Python more powerful than C++?  Hi, I am beginner in Data Science
Two or more actions in the same form
Two or more actions in the same form  Can I have two or more actions in the same form
how can retrieve more than one values in text field using ajax?
how can retrieve more than one values in text field using ajax?  im using php and ajax. Problem is that i want to search seat numbers bases of batch and semester condition on onchange event eg. if i search batch 2008 and semester
More than 1 preparedStatement object - Java Beginners
More than 1 preparedStatement object  Hey but I want to use more than... java... Thanks  Hi Friend, You can use more than one prepared...*; public class JdbcPreparedstatementAddbatch { public static void main
Can I have multiple main() methods in the same class?
Can I have multiple main() methods in the same class?  Hi, Can I have multiple main() methods in the same class?   Hi, No, We cann't... defined in the class.. For more details related to use of multiple main() method
How can i pass the valus from a JSP to the action class???
How can i pass the valus from a JSP to the action class???  hewllo wevryone... can anyone help me with how i can pass the value of menuId in my JSP and pass it in the action class
more than one struts-config.xml file
more than one struts-config.xml file  Can we have more than one struts-config.xml file for a single Struts application
Writing more than one cards in a WML deck.
created two cards. You can create as many as you want...    Writing more than one cards in a deck.In this lesson
how can i create a data grid - Java Beginners
how can i create a data grid  Nice to ur respose...thnks all of u plz help me i want make a datagrid but i have no idea about this how can i create datagrid. and how can i connect to the database plz help me give
More than one Faces Configuration file
More than one Faces Configuration file  Is it possible to have more than one Faces Configuration file
create a class
create a class  plz provide any example related to class
Implementing more than one Job Details and Triggers
Implementing more than one Job Details and Triggers... will learn how to implement more than one triggers and jobs with a quartz... of more than one job details and triggers. Description of program:ADS
Apply more than one xsl for single XML
Apply more than one xsl for single XML  How to apply more than one xsl for same xml file
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need...*; import java.sql.*; import javax.swing.*; import java.awt.event.*; class...";, "root", "root"); Statement st=con.createStatement(); int i
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need...*; import java.sql.*; import javax.swing.*; import java.awt.event.*; class...";, "root", "root"); Statement st=con.createStatement(); int i
how can i draw line between two panel contaning circle and line between their center?
how can i draw line between two panel contaning circle and line between their center?   how can i draw line between two panel contaning circle and line between their center
Use of "|" separator for selecting more than one path
Use of  "|" separator for selecting more than one path       You can execute.... It allows you more flexibility by allowing you to execute multiple expressions
How to Display Duplicate elements from more than one List in java?
How to Display Duplicate elements from more than one List in java?  How to Display Duplicate elements from more than one List in java? //I mean common elements from two List? Ex: List a1=new ArrayList(); a1.add(50
I want to know how can I create sessionfactory in hibernate 4 (latest version)
I want to know how can I create sessionfactory in hibernate 4 (latest version)  Hello, I want to create sessionfactory in hibernate 4 (latest version) and I would like your help for it..An example would be of great help
How to write more than 65536 rows in single excel file but more than 1 sheets?
?  Hi, i want to write more than 65536 rows in single excel file but more than 1 sheets.. now i can write only less than 65536 rows.. but in my office db having more than 1 crore data.. pls help me... here is my code.. public class
to create a java class and methods
to create a java class and methods  How to create a java class without using the library class to represent linked lists of integers and also provide it with methods that can be used to reverse a list & append two lists.Also
How to create a class in java
How to create a class in java  I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java
objects create at run time - Java Interview Questions
of the rectangle class. In real-world objects share two characteristics: They have all...objects create at run time  how to create objects at runtime,other than instantiation.  Hi friend, Object : Objects are the basic run
class with in its own objects?
class with in its own objects?  Is it a good idea to declare a class with in its own objects
problem in sending more than 500 values to a jsp page
problem in sending more than 500 values to a jsp page  when i am trying to send more than 500 values from a html form to a jsp page browser is showing that server is not sending any data...I have configured tomcat5.5
how to handle action events in case of more than one JFrame
how to handle action events in case of more than one JFrame   I have... in it to improve the interactivity of the game, i.e i have added two #JDialog named... contains three java files namely 1. Engine.java 2. Snake.java 3. Gameoard.java when i
how i connect two page
how i connect two page  strong textlink text
Two forms submission to one Action Class in Struts2.0
Two forms submission to one Action Class in Struts2.0  Hi, I have two forms.I want to submit two forms with only one submit button to the same action, same method. How can i get this. Please reply me
PHP Comparison Objects
two objects of class (same or different). There are mainly = =, = = = operators are used to compare two objects, and instance of operator can be used also. ADS...;  ADS_TO_REPLACE_16 Output: Comparison of two objects of same class
How to get more than one value from ajax
How to get more than one value from ajax  I have multiple select list box in php. i filled the value using ajax. how to get different value to fill the same list box Ex. option value as id (adsbygoogle
I/O stream class.
I/O stream class.  Explain the hierarchy of Java I/O stream class.   Hierarchy of Java I/O streams Have a look at the following link: Java I/O
My Base Class is Changing every time in my code. How I can overcome this?
My Base Class is Changing every time in my code. How I can overcome this? ... the answer. I have a base class, 'GeneratorBaseClass' that is extended by Generator. The question I was asked was about creating a new base class
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns  i am 3rd year cs student in ethiopia. i have a view in my database schema so how can i create a jtable to look the view result
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...   ...) { images[i].setDescription(aray[i]); } } //Create
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects

Ads