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
What do you mean by singleton class in java?
What is the maximum size of a string in java?
Why do we need strings in java?
What does flagged out mean?
How thread scheduler schedule the task?
Why enumeration is faster than iterator?
What are loops in java? What are three types of loops?
Is singleton set an interval?
What is generics in java interview questions?
Explain the difference between jvm and jre?
Is java a compiler?
Explain illegalmonitorstateexception and when it will be thrown?
Why do we create threads in java?
What are different types of expressions?
what do you mean by classloader in java?