How can we create a object of a class without using new
operator.



How can we create a object of a class without using new operator...

Answer / mamatha

There are different ways to create objects in java:

1. Using new keyword
This is the most common way to create an object in java.

MyObject object = new MyObject();

2. Using Class.forName()

MyObject object = (MyObject) Class.forName("subin.rnd.MyObject").newInstance();

3. Using clone()
The clone() can be used to create a copy of an existing object.

MyObject anotherObject = new MyObject();
MyObject object = anotherObject.clone();

4. Using object deserialization
Object deserialization is nothing but creating an object from its serialized form.

ObjectInputStream inStream = new ObjectInputStream(anInputStream );
MyObject object = (MyObject) inStream.readObject();

5.By using getInstance();

Is This Answer Correct ?    38 Yes 8 No

Post New Answer

More Core Java Interview Questions

What is a arraylist in java?

0 Answers  


what is Assertion?

4 Answers   Wipro,


What is static variable and static method?

32 Answers   Accenture, Prolific, Prolifics, TCS, TNH,


Does java return by reference?

0 Answers  


Why is stringbuffer thread safe?

0 Answers  






explain System.out.println()

12 Answers   CTS,


Which is easier netbeans or eclipse?

0 Answers  


Why java is a platform independent? Explain

0 Answers  


How can you avoid serialization in child class if the base class is implementing the serializable interface?

0 Answers  


Is binary a low level language?

0 Answers  


Difference between abstract class and Interfaces?

7 Answers   CTS, iFlex, PA Consulting, Sai Softech, Value Chain,


What is the inheritance?

0 Answers  


Categories