• 2022-06-08
    设有以下定义和程序: #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();
  • C

    举一反三

    内容

    • 0

      定义类Block和类Demo,运行Demo的输出结果是。 class Block{ {//代码1 System.out.print("1"); } static{//代码2 System.out.print("2"); } {//代码3 System.out.print("3"); } public Block() {//代码4 System.out.print("4"); } static void show() {//代码5 System.out.print("5"); } static {//代码6 System.out.print("6"); } } //定义测试类Demo public class Demo { public static void main(String[] args) { new Block().show(); new Block() } }

    • 1

      阅读以下程序class A{protected: int a=0;public: A(){a=1;}};class B:virtual public A{public: B(){a++;}};class C:virtual public A{public: C(){a+=2;}};class D:public B,public C{public: void print(){ cout< A: 0 B: 1 C: 3 D: 4

    • 2

      下列程序的执行结果是______。 class A1 implements Runnable { public void run() { for(iht i = 0; i < 10; i++) { System.out.println("i =" + i); if(i == 3) break; } } } public class ex38 { public static void main(String[] args) { Thread th1 = new Thread(new A1()); th1.start (); } } A: i=1 i=2 i=3 i=4 B: i=1 i=1 i=1 i=1 C: i=0 i=1 i=2 i=3 D: i=1 i=2 i=3

    • 3

      在下列类族声明的代码中,正确的访问类N的成员a的语句为 。 class N { public: int a; void display(){cout<<″A::a=”<<a<<endl;} }; class A:public N { public: int a1; }; class B:public N { public: int a2; }; class C :public A,public B { public : int a3; void show{cout<<″a3=″<<a3<<endl;} }; int main { C c1;//定义C类对象c1 ┆ }

    • 4

      public class Example {     public static void main(String&#91;&#93; args) {         new Father () {             public void show() {                 System.out.println("helloworld");             }         }.show();     } } class Father {     public void show() {         System.out.println("hellofather");     } }