本帖最后由 陈嘉宾 于 2012-6-11 18:32 编辑
编译过不去了。。提示无法从静态上引用非静态方法。哪位高手帮我看看。。谢谢
class fanshe
{
public static void main(String[] args) throws Exception
{
Person obj= Person.class.getConstructor (String.class,int.class).
newInstance("xp",18);
System.out.println(Person.getName()+Person.getAge());
}
}
class Person
{
private String name;
private int 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;
}
public Person(){}
public Person(String name,int age){
this.name=name;
this.age=age;
}
} |