Home Answers Viewqa Java-Interview-Questions can i restrict a class that it will not allows create more than two objects

 
 


balu
can i restrict a class that it will not allows create more than two objects
2 Answer(s)      5 years and 4 months ago
Posted in : Java Interview Questions

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 Pages:
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
Objects
writing the class definition, you can use it to create objects of that class... is an additional information about Objects that we can create multiple objects....  Real-world objects share two characteristics: They all have state
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
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
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
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: Here, we
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
Classes and Objects
the main() method.  A class can have more than one instances (objects), let us... can contains both data as well as methods. A simple class having no method must... techniques. A class defines the properties of  objects and methods used
Exceptions - More
- More Kinds of Exceptions There are many exceptions, but they can..., you can either use an assert or throw an exception. I often use something like... exceptions You can also create your own exceptions. [Not yet written] References
Classes and Objects
class starts from the main() method.  A class can have more than one instances (objects), let us consider a class employee having the employee details... technique. A class can contains both data as well as methods. A simple class
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
Writing more than one cards in a WML deck.
. You can create as many as you want, but the card ids...    Writing more than one cards in a deck.In this lesson
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
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
Counting Objects Clandestinely - Java Tutorials
missing a few African countries, ok, it's worse than missing, I only have South... Java programmers ;-). Counting Objects Clandestinely A few months ago I...(); counting = true; } } You can now know exactly how many objects were
Error in connecting to the mySQL database in TOMCAT using more than one PC (database connection pooling)
the same application/database, I get a java.lang.NullPointer Exception. Can you help me? I tried using DriverManager.getConnection, and I can work with two or more...Error in connecting to the mySQL database in TOMCAT using more than one PC
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
WANT TO RESTRICT EDITING AFTER A SET OF DATE
WANT TO RESTRICT EDITING AFTER A SET OF DATE  localhost : Server version: 5.0.51b-community-nt phpMyAdmin - 2.11.7 hello guys, i have to continue my work more complex.. but i dont have any idea to do that... i want
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
Avanced objects - Java Beginners
. Extend the Human class to create two new classes Adult and Child. 9. Make sure.... They should all be mammals but have some unique characteristics. 7. Create a Family class... specifying the movie rating. 12. Create a MovieRating class that contains
Serializing Objects Into Database - java tutorials
", where I look at how we can serialize objects into a database using JDBC. Thank... Objects Into Database A problem I faced a few months ago, before JDK 1.3... tested it with less than 2000 bytes the first time I wrote the code
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
JSP Implicit Objects
automatically, we do not need to create them explicitly. Since these objects... allows direct access to the HTTPServletResponse class object. Session... JSP Implicit Objects      
Hi.. how to write more than one sheets in a excel file... pls anybody help me....
Hi.. how to write more than one sheets in a excel file... pls anybody help me....  i can write only one sheet in a excel file.. but i want to write more than one sheets.. For example: first sheet have complete mean automatically
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
More About the CronTrigger
More About the CronTrigger       The CronTriggers are more useful than the SimpleTrigger, if we... weekday. The Wild-cards ('* ' character) that can be used for inserting the every
Class
is the object of the rectangle class. In real-world objects share two... name is Construct. In the Construct class two objects (a and b) are created...;  Class : Whatever we can see in this world all the things
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
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: Hibernate Tutorial Thanks
Objects - Java Beginners
) { //Declare and create a Headmain object //and Three ArmsMain objects... a class to represents a human. The head, arms and legs should be properties of the human and should be represented by separate objects. All of your objects
JSP Implicit Objects
, the developer do not need to create them explicitly. Since these objects are created... of this objects can be set in the deployment descriptor (web.xml) inside... and is an instance of java.lang.Throwable class. This object allows
Java Interview Questions - Page 11
;    Question: What class allows you to read objects directly from a stream?  Answer: The ObjectInputStream class... for two String objects with identical values not to be equal under
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... = = = checks two objects and returns true if both refers two the same object a class
Comparing two Dates in Java
Comparing two Dates in Java       In  this example we are going to compare two date objects... second of creation of firstDate. Now in our example program we can compare these two
Creation of MultiThreads
;    Like creation of a single thread, You can also create more than one thread (multithreads) in a program using class Thread..., lets create the same program implenting the Runnable interface: class
Creation of Multiple Threads
;    Like creation of a single thread, You can also create more than one thread (multithreads) in a program using class Thread or implementing... create the same program implenting the Runnable interface: class MyThread1
combine two pdf files
combine two pdf files       In this program we are going to tell you how you can read a pdf file and combine more than one pdf into one.  To make a program over this, firstly
Creation of MultiThreads
; Like creation of a single thread, You can also create more than one thread (multithreads) in a program using class Thread or implementing interface.... It means, you can use either class Thread or interface Runnable to implement thread
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
how can create a jar file - Java Beginners
how can create a jar file  plz any one help me which file can i create the jar file plz give exact command  Hi The basic format... that you want to create a JAR file. * The f option indicates that you want
Objects in Java
Objects in Java Whatever we can see in this world all the things are a object... as a class. All the objects are direct interacted with its class that mean... on the particular properties of the class or its group. We can understand about the class
Java Notes: Vectors
to use each. The description below is for the (new) Vector class. Vectors can... to define your own class. To Create a Vector You must import either import..., Object) Insuring use of the new API When you create a Vector, you can assign
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
More About Triggers
(not java.util.Calendar) objects can be associated with triggers object at the time... More About Triggers      ... of triggers. As we know that the trigger objects are used for executing the jobs
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
Create Progress Bar in SWT
Bar. SWT allows to create a Progress bar by providing the class ProgressBar of package org.eclipse.swt.widgets. With the use of this class, you can display... Create Progress Bar in SWT   
restrict jtable editing
restrict jtable editing  How to restrict jtable from editing or JTable disable editing?   public class MyTableModel extends AbstractTableModel { public boolean isCellEditable(int row, int column
Mapping objects in XML - Spring
Mapping objects in XML   Hello, I´ve read that you can define... Ok, but, if I want to set a different value for "name" each time I create the object... How can I define the XML? I don´t understand the utility about
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