问答题
本程序的功能是定义类中带有参数的构造方法exam_19()和普通方法printInfo(),并定义类的对象temp,程序中将字符串“Jim”和整数19在定义对象时作为构造方法的参数传递给类,然后调用方法printInfo()打印传递的变量(如Jim已经有19岁了),请将程序中空缺部分填写适当内容,使程序能正确运行。
public class exam_19{
String name;
int age;
public exam_19(______){
this.name=name;
this.age=age;
}
______printInfo(){
System.out.println(name+"已经有"+age+"岁了.");
}
public static void main(String[] args){
String name="Jim";
int age=19;
______=new exam_19(name, age);
temp.printInfo();
}
}
【正确答案】String name, int age
public void
basic temp
【答案解析】