How many ways to get the instance of classI know 3 ways1)using new operator2)class.forName()3)getInstance()is there any outher ways?

Showing Answers 1 - 6 of 6 Answers

freedeus

  • Feb 14th, 2007
 

First of all, Class.forName(String className) is not actually a way to instantiate a class. It is a way to load a class and return the particular "Class" object associated with the loaded class. In fact, Class.forName() internally calls the associated ClassLoader's loadClass() method.The other methods, that I can recall are-

1) Cloning a given object to get a cloned instance.

2) Deserializing a serialized object to get the instance.But both the ways above, have some constraints.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions