Link to home
Create AccountLog in
Avatar of roy_sanu
roy_sanuFlag for India

asked on

Instantiate objects without using new operator

Hello,

Somebody asked me this question

How can one  Instantiate an objects without using new operator

Thanks
Avatar of mccarl
mccarl
Flag of Australia image

There are a couple of ways.

Here are *some* examples...
String test = "This is a test string.";

Double dbl = 42.9;

Open in new window

Also, do you mean something like this...
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();

Open in new window

In the above, two object have been instantiated without explicitly using the new operator. However, do note that somewhere in those static factory methods, the new operator would have been used to actually instantiate the objects that were returned.
ASKER CERTIFIED SOLUTION
Avatar of Valeri
Valeri
Flag of Bulgaria image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer