How do you create objects without using "new" operation.? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do you create objects without using "new" operation.?

1st Mar 2017, 5:28 PM
Gowtham S Reddy
Gowtham S Reddy - avatar
3 Answers
+ 2
I think new objects are created without using the new operator if you clone an object or deserialize from an object stream.
1st Mar 2017, 7:54 PM
Tamás Barta
Tamás Barta - avatar
+ 1
There is always somewhere(internally) the new operator called. However many methods return objects, e.g. Files.newBufferedReader (Path p). (a method that should be used since java 7 instead of : new BufferedReader (File f)) Also when you init a String you don't call new: String s="hi"; But generally there is always somewhere the new operator called. Why do you need this?
1st Mar 2017, 5:35 PM
No One
No One - avatar
0
just to know...new is the only way to create objects or others options we can use it..
1st Mar 2017, 5:39 PM
Gowtham S Reddy
Gowtham S Reddy - avatar