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...

what is class.forname() and how it will be useful ?

Answer Posted / pradip

class.forname() is used to create an instance of a class on
the basis of the name in string format instead of doing new
Class. One of its use is in cases where you have some
generic (common) logic to call methods of some classes just
on the basis of the names of the class and the method. The
example of reflection shown below uses the logic.

Eg:
performAction(String className, String methodName) {
Class class = Class.forName(className);
MethodUtils.invokeMethod(class.newInstance, methodName,
null);
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a constructor, constructor overloading in java?

953


What is polymorphism and what are the types of it?

938


If A Class Is Declared Without Any Access Modifiers, Where May The Class Be Accessed?

1115


Why is String immutable?

1010


Add a value x to array from index l to r where 0 <= l <= r <= n-1

1022


What is volatile data type?

946


How do generics work?

888


When do we use synchronized methods in java?

987


What is class variable java?

954


What classes of exceptions may be thrown by a throw statement?

907


How do you use compareto method?

943


What is java lang string?

941


Is nullpointerexception checked or unchecked?

964


Is it safe to install java on my computer?

1042


Can you have two constructors in java?

897