http://www.verejava.com/?id=16995076368233
package com.reflect;
public class TestClass
{
public static void main(String[] args)
{
try
{
Class c=Class.forName("com.entity.Student");
Object obj=c.newInstance();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (InstantiationException e)
{
e.printStackTrace();
} catch (IllegalAccessException e)
{
e.printStackTrace();
}
}
}
package com.entity;
public class Student
{
private String name;
private int age;
private int money;
private String address;
private Course course;
public Student()
{
super();
System.out.println("student");
}
public Student(String name, int age)
{
super();
this.name = name;
this.age = age;
System.out.println(this.name+","+this.age);
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
private String getHello()
{
return "hello";
}
}