第七章测试1.
定义类关键字class
A:对 B:错
答案:A
2.
类体定义包括属性和方法两个部分
A:对 B:错 3.
类定义中的属性必须给初始值。( )
A:对 B:错 4.
补全类Test下划线处的代码,程序执行结果是显示学生信息。
public class Test{
public static void main(String [] args){
Student s = new Student();
}
}
class Student{
String name = "zhangsan";
int age = 20;
double grade = 80;
void display(){
System.out.println("name:" + name);
}
}
A:Student.display() B:s.display() C:display(). D:其他 5.
补全类Test下划线处的代码,程序功能是显示手机信息
public class Test{
public static void main(String [] args){
m.display();
}
}
class MobilePhone{
private String brand="Apple";
private String code="13800000000";
public void display(){
System.out.println("Brand:" + brand);
System.out.println("Code:" + code);
}
}
A:MobilePhone m B:其他 C:MobilePhone mf = new MobilePhone() D:MobilePhone m = new MobilePhone()