设有以下定义和程序: #include<iostream.h> class A1 public: void show 1() cout<<" class A 1"<<end1; class A2:public A1 public: void show20 cout<<"class A2"<<end1; ; class A3:protected A2 public: void show3() cout<<"class A 1 "<<end1; ; void main()
A: A1 obj1;A2 obj2;A3 obj3;则以下不合语法的调用语句是(
B: )。A) obj1.show1();
C: B) obj2.show1();
D: C) obj3.show1();
E: D) obj2.show2();
A: A1 obj1;A2 obj2;A3 obj3;则以下不合语法的调用语句是(
B: )。A) obj1.show1();
C: B) obj2.show1();
D: C) obj3.show1();
E: D) obj2.show2();
举一反三
- 下面程序的结果是( )。 #include<iostream.h> class A int a; public: A: A():a(1) B: void showa()cout<<a; C: ; D: Class Bint a; E: public: F: B():a(2) G: void showa()cout<<a; H: ); I: class C:public A,public Bint a; J: public: K: C():a(3) L: void showa()cout<<a; M: ; N: void main()C c; O: c.showa(); P: A) 1 Q: B) 2 R: C) 3 S: D) 程序有错误
- 下列程序运行结果是 public class Demo { public static void main(String[] args) { Object obj=new Father(){ public void show(){ System.out.println("helloworld"); } }; obj.show(); } } class Father{ public void show(){ System.out.println("hello father"); } }
- 下列程序运行结果是( ) public class Demo { public static void main(String[] args) { Object obj=new Father(){ public void show(){ System.out.println("helloworld"); } }; obj.show(); } } class Father{ public void show(){ System.out.println("hello father"); } }
- class MyException extends (1) { } public class Demo { public static void main(String[] args) { try { show(); } catch ( (2) e) { e.printStackTrace(); } } public static void show() (3) MyException { throw new MyException(); } 以上程序,创建了一个自定义异常(编译异常),请补全空白处代码
- 有如下程序: #include<iostream> using namespace std; class A{ public: static int a; void init( ){a=l;} A(int a=2){init( );a++;} }; int A::a=0; A obj; int main( ){ cout<<obj.a; return 0; } 程序的输出结果是 A: 0 B: 1 C: 2 D: 3