设Base1、Base2 类为Derived类的基类,Print()为Base1、Base2中定义的虚函数,下列函数定义中不能实现动态多态性的是:
A: void Fun1(Base1 *ob) {ob->Print();}
B: void Fun2(Base2 *ob) {ob->Print();}
C: void Fun3(Base1 &ob) {ob.Print();}
D: void Fun1(Base1 ob){ob.Print();}
A: void Fun1(Base1 *ob) {ob->Print();}
B: void Fun2(Base2 *ob) {ob->Print();}
C: void Fun3(Base1 &ob) {ob.Print();}
D: void Fun1(Base1 ob){ob.Print();}
举一反三
- 对于一下程序,其运行结果为 class Base{ public Base(){ System.out.print("C"); } } class Base2 extends Base{ public Base2(){ System.out.print("B"); } } public class TestDemo extends Base2{ int m=1; public TestDemo(){ System.out.println("A"); } public static void main(String args[]){ TestDemo t = new TestDemo(); } }
- 【多选题】(8-1)(1)在包中qzy.jsu定义了如下类Base; package qzy.jsu; public class Base{ public void show1( ) { } protected void show2( ) { } void show3( ) { } private void show4( ) {}; } (2)在包中qzy.student定义了类Sub,则 1 处
- (6-2)以下代码会出现编译错误。 class Base{ public Base () { System.out.println("1"); } public void Base () { System.out.println("2"); } }
- 【多选题】(8-2) (1)在包qzy.jsu中定义了如下类Base: package qzy.jsu; class Base{ public void show1( ) { } protected void show2( ) { } void show3( ) { } private void show4( ) {}; } (2)在qzy.jsu包中定义了如下类Sub,则 1 处的正确代码是(
- (8-2)(1)在包中qzy.jsu定义了如下类Base; package qzy.jsu; class Base{ public void show1() { } protected void show2() { } void show3() { } private voidshow4(){}; } (2)在包中qzy.student定义了类Sub,则①处的正确代码是( )。 package qzy.student; import qzy.jsu.*; public class Sub extends Base{ public void show() { ① } }