java getname
类class getName()方法 (Class class getName() method)
getName() method is available in java.lang package.
getName()方法在java.lang包中可用。
getName() method is used to return the name of the classes, an interface, a primitive type, a void type, an array class denoted by this Class object.
getName()方法用于返回类的名称,接口,原始类型,无效类型以及由此Class对象表示的数组类。
getName() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
getName()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
getName() method does not throw an exception at the time of returning the name of classes or an interface.
在返回类或接口的名称时, getName()方法不会引发异常。
Syntax:
句法:
public String getName();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of this method is String, it returns the name of the class or an interface.
该方法的返回类型为String ,它返回类或接口的名称。
Example:
例:
// Java program to demonstrate the example
// of String getName() method of Class
public class GetNameOfClass {
public static void main(String[] args) {
Thread th = new Thread();
// Get Class object of Thread
Class cl = th.getClass();
// It return the name of the class Thread
String class_name = cl.getName();
// Display Class Name
System.out.println("Class Name :: " + class_name);
}
}
Output
输出量
Class Name :: java.lang.Thread
翻译自: https://www.includehelp.com/java/class-class-getname-method-with-example.aspx
java getname