![]() |
VOOZH | about |
The forName() method of java.lang.Class class is used to get the instance of this Class with the specified class name. This class name is specified as the string parameter.
Syntax:
public static Class<T> forName(String className) throws ClassNotFoundException
Parameter: This method accepts the parameter className which is the Class for which its instance is required.
Return Value: This method returns the instance of this Class with the specified class name.
Exception: This method throws following Exceptions:
Below programs demonstrate the forName() method.
Example 1:
Class represented by c1: class java.lang.String
Example 2:
Class represented by c1: class java.lang.Integer
Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#forName-java.lang.String-