Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 does function identity () do?

0 Answers  


What is the role of the java.rmi.naming class?

0 Answers  


What is the use of accept () method in java?

0 Answers  


What is a double vs float?

0 Answers  


Why only one Class is public in one file? Explain in details. Thanks in Advance.

12 Answers  


What is boolean example?

0 Answers  


How to perform binary search in java?

0 Answers  


Features of JAVA ? In which version of java synchronizedXXX() methods are included in Collections class.

1 Answers   NIIT,


Which is the best way of exception handling?

2 Answers   Oracle,


Can we create a class inside a class in java?

0 Answers  


What is meant by inheritance and what are its advantages?

0 Answers  


What are exceptions

0 Answers   Futures First,


Categories