Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

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 type parameter in java?

143


Explain the difference between the public, private, final, protected, and default modifiers?

168


What are constants?

215


How do you bind variables?

151


What is the difference between serial and throughput garbage collector?

187






What are the important features of Java 11 release?

218


When a thread is executing synchronized methods , then is it possible to execute other synchronized methods simultaneously by other threads?

216


Is arraylist a class in java?

146


Explain about java sdk?

204


What is connection class in java?

153


What are the types of methodology?

164


Difference between keyword and identifier.

198


What does indexof mean?

162


Can substring create new object?

158


What is volatile keyword in java

225