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 light weight and heavy weight components?
What is java util function?
how to write a program for sending mails between client and server
What is the finalize method do?
What is the file extension for java?
What is meant by local variable and instance variable?
Does constructor creates the object ?
What do you mean by scope of variable?
How to sort elements in a parallel array in java?
What is private public protected in java?
What is the main method java?
What is a local, member and a class variable?
How to create a fecelet view?
Which data type is a class in java?
What is the purpose of a parameter?