网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
class ClassA { public int numberOfinstances; protected ClassA(int numberOfinstances) { this.numberOflnstances = numberOfinstances; } } public class ExtendedA extends ClassA { private ExtendedA(int numberOfinstances) { super(numberOflnstances); } public static void main(String[] args) { ExtendedA ext = new ExtendedA(420); System.out.print(ext.numberOflnstances); } } Which is true?()
- A、 420 is the output.
- B、 An exception is thrown at runtime.
- C、 All constructors must be declared public.
- D、 Constructors CANNOT use the private modifier.
- E、 Constructors CANNOT use the protected modifier.
参考答案
更多 “ class ClassA { public int numberOfinstances; protected ClassA(int numberOfinstances) { this.numberOflnstances = numberOfinstances; } } public class ExtendedA extends ClassA { private ExtendedA(int numberOfinstances) { super(numberOflnstances); } public static void main(String[] args) { ExtendedA ext = new ExtendedA(420); System.out.print(ext.numberOflnstances); } } Which is true?() A、 420 is the output.B、 An exception is thrown at runtime.C、 All constructors must be declared public.D、 Constructors CANNOT use the private modifier.E、 Constructors CANNOT use the protected modifier.” 相关考题
考题
已知如下类定义: class Base { public Base (){ //... } public Base ( int m ){ //... } protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下哪句可以正确地加入子类中?()
A.private void fun( int n ){ //...}B.void fun ( int n ){ //... }C.protected void fun ( int n ) { //... }D.public void fun ( int n ) { //... }
考题
classClassA{publicintnumberOfinstances;protectedClassA(intnumberOfinstances){this.numberOflnstances=numberOfinstances;}}publicclassExtendedAextendsClassA{privateExtendedA(intnumberOfinstances){super(numberOflnstances);}publicstaticvoidmain(String[]args){ExtendedAext=newExtendedA(420);System.out.print(ext.numberOflnstances);}}Whichistrue?()A.420istheoutput.B.Anexceptionisthrownatruntime.C.Allconstructorsmustbedeclaredpublic.D.ConstructorsCANNOTusetheprivatemodifier.E.ConstructorsCANNOTusetheprotectedmodifier.
考题
若有以下程序:includeusingnamespacestd;classA{private:int x; public:int x;void s
若有以下程序: #include<iostream> usingnamespacestd; classA { private: int x; public: int x; void setx(int i) { x=i; } int getx() { return x; } }; class B:public A { private: int m; public: int p; void setvalue (int a,int b,int C) { setx(A) ; z=b; m=c; } void display() { cout<<getx()<<","<<z<<","<<m<<end1; } }; int main() { B obj; obj.setvalue(2,3,4); obj.display(); return 0; } 程序运行以后的输出结果是A.产生语法错误B.2,3,4C.2,2,2D.4,3,2
考题
有如下程序:includeusing namespace std;classA{public:A(){cout
有如下程序: #include<iostream> using namespace std; classA { public: A(){cout<<"A";} }; class B{public:B(){cout<<"B";}}; class C:public A { B b; public: C(){cout<<"C";} }; int main(){C obj;return 0;} 执行后的输出结果是( )A.ABCB.BACC.ACBD.CBA
考题
请按下面注释的提示,将类B的构造函数定义补充完整。classA{int a;public:A(int aa=0) {a=aa;)};Class B:public A{int b;A c;public://用aa初始化基数A,用aa+1初始化类对象成员cB(int aa): (b=aa+2)};
考题
有以下程序:includeusing namespace std;classA{private: int x;public: A(int a) {x
有以下程序: #include<iostream> using namespace std; class A { private: int x; public: A(int a) { x=a; } friend class B; }; class B { public: void print(A a) { a.x--; cout<<a, x<<end1; } }; int main () { A a(10); B b; b.print (a) ; return 0; } 程序执行后的输出结果是( )。A.9B.10C.11D.12
考题
下面程序段的输出结果为 package test; public class ClassA { int x=20; static int y=6; public static void main(String args[]) { ClassB b=new ClassB(); b.go(10); System.out.println("x="+b.x); } } class ClassB { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }A.x=10B.x=20C.x=6D.编译不通过
考题
下面这个程序的结果是includeclass A{private:int a;public:void seta( );int geta
下面这个程序的结果是 #include<iostream.h> class A { private: int a; public: void seta( );int geta( );}; void A::seta( ) { a = 1;} int A::geta( ) {return a;} classA.1B.2C.随机输出1或2D.程序有错
考题
在下列源代码文件Test.java中,正确定义类的代码是( )。A.pblic class test { public int x=0; public test(int x) { this. x=x;} }B.public class Test { public int x=0; public Test(int x) { this. x=x;} }C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }
考题
下面程序段的输出结果为( )。 package test; public class ClassA { int x=20: static int y=6; public static void main(String args[]) { ClassB b=new ClassB; go(10); System.out.println("x="+b.x); } } class ClassB { int X; void go(int y) { ClassA a=new ClassA; x=a.Y ; } }A.x=10B.x=20C.x=6D.编译不通过
考题
下面程序中错误之处是 ______。 include classA{private:intxl;protected:intx2;publ
下面程序中错误之处是 ______。include<iostream.h>class A{private:int xl;protected:int x2;public:int x3;};class B: public A{private:int b1;protected:int b2;public:int b3;void disp(){cout<<x1<<b2<<end1;} //Avoid set(int i){x3=i;} //B};void main()B bb;bb. a3=10 //Cbb. b3=10 //D}
考题
下面程序段的输出结果为 package test; public class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println(”x=”+b.x); } } class Class B { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }A.x=10B.x=20C.x=6D.编译不通过
考题
请找出下列程序中错误之处 ______。 include classA{private: intx1;protected: int
请找出下列程序中错误之处 ______。#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:} //Avoid set(int i) {x2=i;} //B};void main() {B bb;bb.x3=10; //Cbb.y3=10; //D}A.AB.BC.CD.D
考题
在下列源代码文件Test.java中, ( )是正确的类定义。A.public class test{B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }C.public class Test extends T1,T2{D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}
考题
有以下源程序: package test; public class ClassA { int x=20; static int y=6; public static void main(String args[]) { ClassB b=new ClassB(); b.go(10); System.out.println("x="+b.x); } } class ClassB { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } } 上述源程序文件的运行结果为( )。A.x=10B.x=20C.x=6D.编译不通过
考题
在下列源代码文件Test.java中,哪个选项是正确的类定义?A.public class test{ public int x=0; public test(int x ) { this.x=x; } }B.public class Test { public int x=0; public Test(int x ) { this.x=x; } }C.public class Test extends T1 T2 { public int x=0; public Test(int x){ this.x=x; } }D.protected class Test extends T2 { public int x=0; public Test(int x) { this.x=x; } }
考题
class A { protected int method1(int a, int b) { return 0; } } Which two are valid in a class that extends class A?() A、 public int method1(int a, int b) { return 0; }B、 private int method1(int a, int b) { return 0; }C、 private int method1(int a, long b) { return 0; }D、 public short method1(int a, int b) { return 0: }E、 static protected int method1(int a, int b) { return 0; }
考题
10. public class ClassA { 11. public void count(int i) { 12. count(++i); 13. } 14. } And: 20. ClassA a = new ClassA(); 21. a.count(3); Which exception or error should be thrown by the virtual machine?() A、 StackOverflowErrorB、 NullPointerExceptionC、 NumberFormatExceptionD、 IllegalArgumentExceptionE、 ExceptionlnlnitializerError
考题
Which statements concerning the following code are true?() class a { public a() {} public a(int i) { this(); } } class b extends a { public boolean b(String msg) { return false; } } class c extends b { private c() { super(); } public c(String msg) { this(); } public c(int i) {} } A、The code will fail to compile.B、The constructor in a that takes an int as an argument will never be called as a result of constructing an object of class b or c.C、Class c has three constructors.D、Objects of class b cannot be constructed.E、At most one of the constructors of each class is called as a result of constructing an object of class c.
考题
1. class Super { 2. private int a; 3. protected Super(int a) { this.a = a; } 4. } ..... 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { this.a= 5; } 14. } Which two, independently, will allow Sub to compile?()A、 Change line 2 to: public int a;B、 Change line 2 to: protected int a;C、 Change line 13 to: public Sub() { this(5); }D、 Change line 13 to: public Sub() { super(5); }E、 Change line 13 to: public Sub() { super(a); }
考题
public class Parent { int change() {…} } class Child extends Parent { } Which methods can be added into class Child?() A、 public int change(){}B、 int chang(int i){}C、 private int change(){}D、 abstract int chang(){}
考题
public class ClassA { public int getValue() { int value=0; boolean setting = true; String title=”Hello”; (value || (setting title == “Hello”)) { return 1; } (value == 1 title.equals(”Hello”)) { return 2; } } } And: ClassA a = new ClassA(); a.getValue(); What is the result?() A、 1B、 2C、 Compilation fails.D、 The code runs with no output.E、 An exception is thrown at runtime.
考题
public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which two classes use the Shape class correctly?()A、 public class Circle implements Shape { private int radius; }B、 public abstract class Circle extends Shape { private int radius; }C、 public class Circle extends Shape { private int radius; public void draw(); }D、 public abstract class Circle implements Shape { private int radius; public void draw(); }E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
考题
多选题1. class Super { 2. private int a; 3. protected Super(int a) { this.a = a; } 4. } ..... 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { this.a= 5; } 14. } Which two, independently, will allow Sub to compile?()AChange line 2 to: public int a;BChange line 2 to: protected int a;CChange line 13 to: public Sub() { this(5); }DChange line 13 to: public Sub() { super(5); }EChange line 13 to: public Sub() { super(a); }
考题
单选题10. public class ClassA { 11. public void count(int i) { 12. count(++i); 13. } 14. } And: 20. ClassA a = new ClassA(); 21. a.count(3); Which exception or error should be thrown by the virtual machine?()A
StackOverflowErrorB
NullPointerExceptionC
NumberFormatExceptionD
IllegalArgumentExceptionE
ExceptionlnlnitializerError
考题
多选题public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which two classes use the Shape class correctly?()Apublic class Circle implements Shape { private int radius; }Bpublic abstract class Circle extends Shape { private int radius; }Cpublic class Circle extends Shape { private int radius; public void draw(); }Dpublic abstract class Circle implements Shape { private int radius; public void draw(); }Epublic class Circle extends Shape { private int radius;public void draw() {/* code here */} }Fpublic abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
考题
单选题public class ClassA { public int getValue() { int value=0; boolean setting = true; String title=”Hello”; (value || (setting title == “Hello”)) { return 1; } (value == 1 title.equals(”Hello”)) { return 2; } } } And: ClassA a = new ClassA(); a.getValue(); What is the result?()A
1B
2C
Compilation fails.D
The code runs with no output.E
An exception is thrown at runtime.
热门标签
最新试卷