9.82 若已执行语句Class<;?>; p1=Student.class,其中Student定义了两个构造方法:Student(){}; Student(int stuNo){},则下面通过p1 来获取Student类对象的语句中,错误的是( )
A: Object s1 = p1.newInstance();
B: Student s1 = p1.newInstance();
C: Constructor<;?>; cons = p1.getConstructor( new Class[]{int.class});Object obj1 = cons.newInstance(new Object[]{1});
D: Constructor<;?>; cons = p1.getConstructor( int.class);Object obj1 = cons.newInstance(1);
A: Object s1 = p1.newInstance();
B: Student s1 = p1.newInstance();
C: Constructor<;?>; cons = p1.getConstructor( new Class[]{int.class});Object obj1 = cons.newInstance(new Object[]{1});
D: Constructor<;?>; cons = p1.getConstructor( int.class);Object obj1 = cons.newInstance(1);
举一反三
- 设有People和Student两个类,其中People是父类,Student是子类,假设这两个类都有无参的构造方法。有下面两个语句:语句1:People p1 = new Student();语句2:Student s1 = new People();下面哪一个选项是正确的? A: 语句1和2 都正确 B: 语句1和2都错误 C: 语句1正确而语句2错误 D: 语句2正确而语句1错误
- 下面是几条定义类的语句,不能被继承的类是( )。 A: abstract class Student {} B: class Student{} C: public class Student{} D: sealed class Student{}
- 以下有关类的声明,正确的是 A: class Student(object) def __init__(self, name, score): self.name = name self.score = score B: class Student(object) def __init__(self, name, score) self.name = name self.score = score C: class Student(object): def __init__(self, name, score): self.name = name self.score = score D: class Student(object): def __int__(self, name, score): self.name = name self.score = score
- 若已定义int a=5; 下列对(1)、(2)两个语句的正确解释是( ) (1) int *p=&a; (2) *p=a;
- 下面程序运行的结果是 struct Student { public int age; public string name; public Student(int age, string name) { this.age = age; this.name = name; } } class Program { static void Main(string[] args) { Student stu1 = new Student(18, "小方"); Student stu2 = new Student(24, "小刚"); stu2 = stu1; stu1.age = 30; stu1.name = "小燕"; Console.WriteLine("{1},{0}",stu2.age,stu2.name); } }