Student类继承Person类,Teacher类继承Person类,Graduate类继承Student类,则以下创建一个引用,不正确的是( )
A: Student s; Student& rs = s;
B: Graduate g; Student& rg = g;
C: Person e; Student& re = e;
D: Graduate g; Person& rg = g;
A: Student s; Student& rs = s;
B: Graduate g; Student& rg = g;
C: Person e; Student& re = e;
D: Graduate g; Person& rg = g;
举一反三
- Student类是Person类的子类,分析下面语句,转型是否正确: Student s =(Student)new Person("张三", 23);
- 1)设计两个类Student和Teacher2)抽取两个类共同的内容(如:吃饭、睡觉)封装到一个类Person中,各自特有的部分保留在各自类中。3)让学生类继承Person类,老师类也继承Person。4)编写测试类Example01,测试Student类和Teacher是否继承了Person类的成员。
- 【单选题】下列代码段声明了3个类: classPerson{); class Student :public Person{}; class Undergraduate :Student{}; 下列关于这些类之间关系的描述中,错误的是()。 A. 类Person是类Undergraduate的基类 B. 类Undergraduate从类Student公有继承 C. 类Student是类Person的派生类 D. 类Undergraduate是类Person的派生类
- 类Teacher和Student是类Person的子类
- 假设 Student类为Person类的子类,则下面()创建对象是错误的。 A: Studentbase = new Student() B: Personbase = new Person() C: Personchild = new Student() D: Studentchild = new Person();