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
内容
- 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[] args) { new Father () { public void show() { System.out.println("helloworld"); } }.show(); } } class Father { public void show() { System.out.println("hellofather"); } }