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 to create an instance of a class without using "new"
operator? Plz help me out properly.Thank u.

Answer Posted / satchidananda.lanka

Dynamic loading is a technique for programmatically
invoking the functions of a class loader at run time.

Let us look at how to load classes dynamically.

Class.forName (String className); //static method which
returns a Class
The above static method returns the class object associated
with the class name.
The string className can be supplied dynamically at run
time.
Once the class is dynamically loaded the following method
returns an instance of the loaded class. It’s just like
creating a class object with no
arguments.
class.newInstance (); //A non-static method, which creates
an instance of a
//class (i.e. creates an object).

Example as shown below ....

Test test = null ;
String myClassName = "com.test.DynamicLoadingClass" ;
Class testClass = Class.forName(myClassName) ;
test = (Test) testClass.newInstance();

Is This Answer Correct ?    10 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a class in java?

1012


How many bytes are a float?

983


Can we write any code after throw statement?

1053


how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread

1004


What is an accessor?

1688


Does java allow overriding static methods ?

1113


Difference between object and reference?

1174


What is exception handling in java?

1036


What is the final method?

1073


What do you understand by java?

992


What is the best definition for data?

971


What do you mean by platform independence of Java?

1157


What is the purpose of using javap?

1099


Explain why wait(), notify() and notifyall() methods are in object class rather than in thread class?

1008


What is the use of arraylist in java?

1093