1 public class Student {
2 private String name;
3 private Integer age;
4 private Student(String name,Integer age){
5 this.name=name;
6 this.age=age;
7 }
8 public String getName() {
9 return name;
10 }
11 public void setName(String name) {
12 this.name = name;
13 }
14 public Integer getAge() {
15 return age;
16 }
17 public void setAge(Integer age) {
18 this.age = age;
19 }
20 }
1 package com.mingrisoft;
2
3 import java.lang.reflect.Constructor;
4
5 public class NewClassTest {
6 public static void main(String[] args) {
7 try {
8 //获得File类的Constructor对象
9 Constructor<Student> constructor = Student.class.getDeclaredConstructor(new Class[]{String.class,Integer.class});
10 Student t = constructor.newInstance("libing",30);
11 System.out.println(t.getName());
12 } catch (Exception e) {
13 e.printStackTrace();
14 }
15 }
16 }