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.

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

what is bmg file and how to create that files?what will it contailn?

2296


What is arraylist e in java?

1001


How do you achieve polymorphism in java?

934


Can we serialize static variables in java?

1036


Why put method is used?

962


What is java util?

973


What happens when I use / and % with a negative numerator?

995


What is the use of put method?

891


What is use of static in java?

1087


Why are constructors used?

963


Which access specifier can be used with class ?

944


What is java in simple terms?

948


What is compareto?

969


Explain the importance of thread scheduler in java?

953


How do you use spaces in java?

944