?? getconstructordemo.java
字號:
import java.lang.reflect.*;
public class GetConstructorDemo
{
public static void main(String[] args)
{
Class c = Employee.class;
Constructor con[]= c.getConstructors();
//用于獲取構造方法的名字
System.out.println("The Constructors name are:");
for (int i = 0; i < con.length; i++)
{
//獲取構造方法名
String str = con[i].getName();
System.out.println(str);
}
System.out.println("\nThe Constructors are:");
//用于獲取構造方法,并轉換為字符串輸出
for (int i = 0; i < con.length; i++)
{
String str = con[i].toString();
System.out.println(str);
}
}
}
class Employee //自定義類
{
private String name;
private int age;
private String sex;
public Employee() //無參數構造方法
{}
//含參數構造方法
public Employee(String name,int age,String sex)
{
this.name = name;
this.age = age;
this.sex = sex;
}
//獲取自定義類屬性值方法
public String get_name(){return name;}
public int get_age(){return age;}
public String get_sex(){return sex;}
//自定義類改變屬性值方法
public void set_name(String name){this.name = name;}
public void set_age(int age){this.age = age;}
public void set_sex(String name){this.sex = sex;}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -