#1
| |||
| |||
java can any buddy tell me can we make constructer as private in java the progran will run or not ![]() |
#2
| |||
| |||
Have a look here: http://www.javapractices.com/topic/TopicAction.do?Id=40 |
#3
| |||
| |||
If you have a method that has a parameter that can take on only a limited set of values then use typesafe enumeration. Example method Code: public void setMode(TypeSafeEnum mode) { ... } Code: public class TypeSafeEnum { public static final TypeSafeEnum ONE = new TypeSafeEnum(); public static final TypeSafeEnum TWO = new TypeSafeEnum(); public static final TypeSafeEnum THREE = new TypeSafeEnum(); public static final TypeSafeEnum FOUR = new TypeSafeEnum(); private TypeSafeEnum() {} } |
#4
| |||
| |||
I make all my constructors private: Code: public class Private { private String string; private Private(String string) { this.string = string; } public String toString() { return string; } } Then I do the following: Code: import java.lang.reflect.*; public class Test{ public static void main(String[] args) throws Exception { Constructor<Private> constructor = Private.class.getDeclaredConstructor(String.class); constructor.setAccessible(true); Private obj = constructor.newInstance("bingo"); System.out.println(obj); } } |
#5
| |||
| |||
ava is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look and feel" of the C++ language, but it is simpler to use than C++ and enforces an object-oriented programming model. Java can be used to create complete applications that may run on a single computer or be distributed among servers and clients in a network. ------------------------------ ages |
#6
| |||
| |||
Java Game Now a days every animated games develop by the help of Java. The looking of Java is attract to people and the man who love the plying games. The use of MVC Pattern by architectural make the Java game more attractive. |
#7
| |||
| |||
Re: java Typically you declare methods private to prevent others from calling them. If you declare a constructor private, you prevent others from creating objects of your class from the outside. This makes sense under some circumstances, e.g. if you implement the so called singleton pattern. This pattern makes sure, that only one object of a certain class exists, so you have to control explicitly, who creates that one and only object. |
![]() |
|
Tags: java |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Java Auto Updater wants me to update java everyday in Windows 7 | minajoh | Windows Software | 4 | 04-09-2013 11:04 PM |
Setting Of Java to The Point At Manual Java | winni | Software Development | 4 | 10-01-2011 10:05 PM |
Java Programming using Adventnet SNMP Java API | ROCKING_Suhas | Software Development | 5 | 17-07-2010 06:52 AM |
Link List Example in Java Sample program in Java | trickson | Software Development | 2 | 04-08-2009 08:23 PM |