We can get class Class object by 3 methods:
- MyClass.class
- obj.getClass
- Class.forName(“className”)
I don’t understood the difference between: MyClass.class and Class.forName("className").
Because both will need Class Name.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
forName is a static method of class “Class”.
we require to provide the fully qualified name of the desired class.
this can be used when name of class will come to known at runtime.
.class is not a method it is a keyword and can be used with primitive type like int.
when Name of Class is known in advance & it is added to project, that time we use ClassName.class