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

Is ++ operator thread-safe in java?

1168


What are structs in java?

1048


What is singleton class example?

1014


Can we compare two strings in java?

1010


What are static blocks in java ?

1089


How will you get the platform dependent values like line separator, path separator, etc., ?

1010


Why for each loop is used?

1002


What are the advantages of passing this into a method instead of the current class object itself?

1662


What do you mean by chromounits in java8?

944


What is double checked locking in singleton?

1043


What are synchronized methods ?

1104


What is difference between char array and string?

1101


What is the difference between menuitem and checkboxmenu item?

1328


Why java is not 100% object-oriented?

1494


Is main is a keyword?

994