Suppose i have an class "employee" having an object obj. then how the obj.getClass().getName() statement will be performed ? And what it should be return ?
The getName() method is a part of File class. This function returns the Name of the given file object. The function returns a string object which contains the Name of the given file object. If the abstract path does not contain any name then a null string is returned.
forName. Returns the Class object associated with the class or interface with the given string name, using the given class loader. Given the fully qualified name for a class or interface (in the same format returned by getName ) this method attempts to locate, load, and link the class or interface.
What Does Class Mean? A class — in the context of Java — is a template used to create objects and to define object data types and methods. Classes are categories, and objects are items within each category. All class objects should have the basic class properties.
The simplest way is to call the getClass() method that returns the class's name or interface represented by an object that is not an array. We can also use getSimpleName() or getCanonicalName() , which returns the simple name (as in source code) and canonical name of the underlying class, respectively.
The getClass()
method gets the actual class of the object, which may be different from the class of the variable holding the object. The getName()
method will return the full package plus class name of that class as a string, like this:
com.company.project.package.MyClass
For example, the following code outputs the above String:
package com.company.project.package; class MyClass extends Object { // some definition } Object o = new MyClass(); System.out.println(o.getClass().getName());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With