Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


balu
can i restrict a class that it will not allows create more than two objects
2 Answer(s)      6 years and 8 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


Advertisement
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
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
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: Hibernate Tutorial Thanks
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
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 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.
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 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
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 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
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
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
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
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
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
More than one Faces Configuration file
More than one Faces Configuration file  Is it possible to have more than one Faces Configuration file
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
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
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 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
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
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
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
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
Advertisements
 

 

 

DMCA.com