There are no instanced of A that will become eligible for garbage collection.
Explicitly setting myA to null marks that instance to be eligible for garbage collection.
Any call on tryIt() causes the private instance of A to be marked for garbage collection.
Private instances of A become eligible for garbage collection when instances of Alpha become eligible for garbage collection.
第1题:
有以下程序: #include <iostream> #include <string> using namespace std; class Y; class X { private: int x; char *strx; public: X(int a, char *str) { x=a; strx=new char[strlen(str)+1]; strcpy(strx,str); } void show(Y &ob) ; }; class Y { private: int y; char *stry; public: Y(int b,char *str) { y=b; stry=new char[strlen(str)+1]; strcpy(stry, str); } friend void X: :show(Y &ob) ; }; void X: :show(Y &ob) { cout<<strx<<", "; cout<<ob, stry<<end1; } int main ( ) { X a(10,"X"); Y b (20, "Y"); a. show(B) ; return 0; } 执行后的输出结果是( )。
A.X,Y
B.a,b
C.X,X
D.Y,Y
第2题:
此题为判断题(对,错)。
第3题:
public class Alpha{ private static Character() ids; public static void main( String[] args){ ids = new Character[args.length]; for (int i=0; i
第4题:
interface Animal { void soundOff(); } class Elephant implements Animal { public void soundOff() { System.out.println(“Trumpet”); } } class Lion implements Animal { public void soundOff() { System.out.println(“Roar”); } } class Alpha1 { static Animal get( String choice ) { if ( choice.equalsIgnoreCase( “meat eater” )) { return new Lion(); } else { return new Elephant(); } } } Which compiles?()
第5题:
10. interface Foo {} 11. class Alpha implements Foo {} 12. class Beta extends Alpha {} 13. class Delta extends Beta { 14. public static void main( String[] args) { 15. Beta x = new Beta(); 16. // insert code here 17. } 18. } Which code, inserted at line 16, will cause a java.lang.ClassCastException?()
第6题:
class Base { Base() { System.out.print(“Base”); } } public class Alpha extends Base { public static void main( String[] args ) { new Alpha(); new Base(); } } What is the result?()
第7题:
Which three will compile and run without exception?()
第8题:
Base
BaseBase
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第9题:
public class Thing { }
public class Thing { public Thing() {} }
public class Thing { public Thing(void) {} }
public class Thing { public Thing(String s) {} }
public class Thing { public void Thing() {} public Thing(String s) {} }
第10题:
Alpha a = x;
Foo f= (Delta)x;
Foo f= (Alpha)x;
Beta b = (Beta)(Alpha)x;
第11题:
a2.m2();
((Beta)a2).m2();
((Alpha)a2).m2();
((Gamma)a2).m2();
第12题:
new Animal().soundOff();
Elephant e = new Alpha1();
Lion 1 = Alpha.get(“meat eater”);
new Alpha1().get(“veggie”).soundOff();
第13题:
下面程序输出的结果为( )。 #inClUde”iostream.h” Class A {public: A(){cout<<“CLASS A”<<endl;} ~A()<)}; class B:public A {public: B(){cout<<”CLASSB”<<endl;} ~B(){}}; void main() {A*p; p=new B; B *q; q=new B;}
A.CLASS A CLASS B
B.CLASS A CLASS B CLASS B
C.CLASS A ClASS B
D.CLASS A CLASS B CLASS A CLASS B CLASS B CLASS B
第14题:
1. public class Target { 2. private int i = 0; 3. public int addOne() { 4. return ++i; 5. } 6. } And: 1. public class Client { 2. public static void main(String[] args) { 3. System.out.println(new Target().addOne()); 4. } 5. } Which change can you make to Target without affecting Client?()
第15题:
Which two allow the class Thing to be instantiated using new Thing()?
第16题:
public class X { public X aMethod() { return this;} } public class Y extends X { } Which two methods can be added to the definition of class Y?()
第17题:
interface Beta {} class Alpha implements Beta { String testIt() { return “Tested”; } } public class Main1 { static Beta getIt() { return new Alpha(); } public static void main( String[] args ) { Beta b = getIt(); System.out.println( b.testIt() ); } } What is the result?()
第18题:
class A { } class Alpha { private A myA = new A(); void dolt( A a ) { a = null; } void tryIt() { dolt( myA ); } } Which two statements are correct?()
第19题:
public class Circle implements Shape { private int radius; }
public abstract class Circle extends Shape { private int radius; }
public class Circle extends Shape { private int radius; public void draw(); }
public abstract class Circle implements Shape { private int radius; public void draw(); }
public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
第20题:
elm elm elm elm
tree elm elm elm
tree elm elm tree
tree elm tree elm
第21题:
只有s1
只有s3
只有s1和s3
只有s1和s4
第22题:
elm elm elm elm
tree elm elm elm
tree elm tree elm
编译失败
第23题:
a2.m2();
((Beta)a2).m2();
((Alpha)a2).m2();
((Gamma)a2).m2();