Object instance = beanClass.newInstance()//beanClass自定义class
Method setJobName = beanClass.getMethod("setJobName", String.class)
method.invoke(instance, "Super Cool Job")//开始设置值。
abstract class Person {String name
int age
String professional
Person(String name,int age,String professional) {
this.name= name
this.age = age
this.professional=professional
}
public abstract void display()
}
class Students extends Person {
int year
Students(String n,int a,String p,int year) {
super(n,a,p)
this.year=year
}
public void display() {
System.out.println("我的姓名="+ name + " " + "我的年龄="+age +" " +"我的专业="+professional+"我的出生年为"+year)
}
}
public class Test5 {
public static void main(String[] args) {
Person p = new Students("男",19,"美术")
Person o = new Students("女",14,"跳舞")
p.display()
o.display()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)