java getclass
对象类最终类getClass() (Object Class final Class getClass())
This method is available in java.lang.Object.getClass().
此方法在java.lang.Object.getClass()中可用。
This method is used to returns the Class class object.
此方法用于返回Class类对象。
The returned Class object is the object that is locked by static synchronized methods of the given class.
返回的Class对象是由给定类的静态同步方法锁定的对象。
This method is final so we can't override it.
此方法是最终方法,因此我们无法覆盖它。
Syntax:
句法:
final Class getClass(){
}
Parameter(s):
参数:
We don't pass any object as a parameter in the method of the Object class.
我们没有在Object类的方法中将任何对象作为参数传递。
Return value:
返回值:
The return type of this method is Class that means this method returns Class object.
该方法的返回类型为Class ,这意味着该方法返回Class对象。
Java程序演示Object Class getClass()方法的示例 (Java program to demonstrate example of Object Class getClass() method)
import java.lang.Object;
public class ObjectClass {
// Java program to demonstrate working of
// getClass() method of Object class
public static void main(String[] args) {
Float fl = new Float(10.f);
Class cl = fl.getClass();
System.out.println("The name of Class of Float fl is : " +
cl.getName());
}
}
Output
输出量
D:\Programs>javac ObjectClass.java
D:\Programs>java ObjectClass
The name of Class of Float fl is : java.lang.Float
翻译自: https://www.includehelp.com/java/object-class-final-class-getclass-method-with-example.aspx
java getclass