1.public classA{2.public String doit(intx,inty){3.return"a";4.}5.6.public String doit(int...vals){7.return"b";8.}9.}And:25.A a=new A();26.System.out.println(a.doit(4,5));What is the result?()
A.Line 26 prints "a" to System.out.
B.Line 26 prints "b" to System.out.
C.An exception is thrown at line 26 at runtime.
D.Compilation of class A will fail due to an error in line 6.
第1题:
若有以下程序:#include <iostream>using namespace std;class A{private: int a;public: void seta(int x) { a=x; } void showa() { cout<<a<<","; }};class B{private: int b;public: void setb(int x) { b=x; } void showb() { cout<<b<<","; }};class C: public A, private B{private: int c;public: void setc(int x, int y, int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; }};int main(){ C c; c.setc(1,2,3); c.showc(); return 0;}程序执行后的输出结果是( )。
A.1,2,3
B.1,1,1
C.2,2,2
D.3,3,3
第2题:
下面程序输出的结果是( )。 #include<iostream> using namespace std; class A{ int X; public: A(int x):x(++x){} ~A(){cout<<x;} }; class B:public A{ int y; public: B(int y):A(y),y(y){} ~B(){cout<<y;}; }; void main(){ B b(3); }
A.34
B.43
C.33
D.44
第3题:
运行下面程序时,会产生什么异常?() public class X7_1_5 { public static void main(String[] args) { int[] z = {1,2,3,4}; int p = z[4]; int x = 0; int y = p/x; } }
A.ArithmeticException
B.ArrayIndexOutOfBoundsException
C.NumberFormatException
D.IOException
第4题:
请找出下列程序中错误之处 ______。
#include<iostream.h>
class A{
private:
int x1;
protected:
int x2;
public:
int x3;
};
class B:public A{
private:
int y1;
protected:
int y2;
public:
int y3;
void disp(){cout<<x1<<y1<<end1:} //A
void set(int i) {x2=i;} //B
};
void main() {
B bb;
bb.x3=10; //C
bb.y3=10; //D
}
A.A
B.B
C.C
D.D
第5题:
若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa,( ) { cout<<a<<", "; } }; class B { private: int b; public: void setb(int x) { b=x; } void showb () { cout<<b<<", "; } }; class C : public A, private B { private: int c; public: void setc(int x,int y, int z) { c=z; sera (x); seth (y); } void showc() { showa(); showb(); cout<<c<<end1; } }; int main () { C c; c.setc(1,2,3); c.showc(); return 0; } 程序执行后的输出结果是( )。
A.1,2,3
B.1,1,1
C.2,2,2
D.3,3,3
第6题:
运行下面程序时,会产生什么异常?() public class X7_1_5 { public static void main(String[] args) { int[] z = {1,2,3,4}; int p = z[4]; int x = 0; int y = 5/x; } }
A.NumberFormatException
B.ArrayIndexOutOfBoundsException
C.IOException
D.ArithmeticException