多选题class A {  }  class Alpha {  private A myA = new A();  void dolt( A a ) {  a = null;  }  void tryIt() {  dolt( myA );  }  }  Which two statements are correct?()AThere are no instanced of A that will become eligible for garbage collection.BExplicitly se

题目
多选题
class A {  }  class Alpha {  private A myA = new A();  void dolt( A a ) {  a = null;  }  void tryIt() {  dolt( myA );  }  }  Which two statements are correct?()
A

There are no instanced of A that will become eligible for garbage collection.

B

Explicitly setting myA to null marks that instance to be eligible for garbage collection.

C

Any call on tryIt() causes the private instance of A to be marked for garbage collection.

D

Private instances of A become eligible for garbage collection when instances of Alpha become eligible for garbage collection.


相似考题
更多“class A {  }  class Alpha {  private A myA = new A();  void ”相关问题
  • 第1题:

    有以下程序:include include using namespace std;class Y;class X{private

    有以下程序: #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


    正确答案:A
    解析:本题考核类的定义和友元函数的应用。①该程序中,类X的成员函数show()在类Y中说明为友元,因此,在该友元成员show()中可以访问类Y的私有成员stry。②成员函数show()的功能就是输出类X的私有成员strx和Y对象ob的私有成员stry,③主函数main()中定义了X类的一个对象a和Y类的一个对象b,并且都进行了初始化。然后调用对象a的成员函数show,输出对象a中私有成员strx中的内容和对象b中私有成员stry中的内容,即字符串stringX和stringY。

  • 第2题:

    以下语句能顺利通过编译: class class1 { private int i=5; //i为私有属性!! } public class class2 { public static void main(String args[]) { class1 cs1=new class1(); System.out.println(cs1.i); } } 。()

    此题为判断题(对,错)。


    答案:错

  • 第3题:

    public class Alpha{  private static Character() ids;  public static void main( String[] args){  ids = new Character[args.length];  for (int i=0; iids[i] = new Character( args[i] );  System.out.print( ids[i] );  }  }  }   What is correct?()  

    • A、 Compilation fails.
    • B、 The code runs with no output.
    • C、 An exception is thrown at runtime.
    • D、 The code runs, outputing a concatenated list of the arguments passed to the program.

    正确答案:A

  • 第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?()  

    • A、 new Animal().soundOff();
    • B、 Elephant e = new Alpha1();
    • C、 Lion 1 = Alpha.get(“meat eater”);
    • D、 new Alpha1().get(“veggie”).soundOff();

    正确答案:D

  • 第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?() 

    • A、 Alpha a = x;
    • B、 Foo f= (Delta)x;
    • C、 Foo f= (Alpha)x;
    • D、 Beta b = (Beta)(Alpha)x;

    正确答案:B

  • 第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?()  

    • A、 Base
    • B、 BaseBase
    • C、 Compilation fails.
    • D、 The code runs with no output.
    • E、 An exception is thrown at runtime.

    正确答案:B

  • 第7题:

    Which three will compile and run without exception?()

    • A、private synchronized Object o;
    • B、void go() {synchronized() { /* code here */ }
    • C、public synchronized void go() { /* code here */ }
    • D、private synchronized(this) void go() { /* code here */ }
    • E、void go() {synchronized(Object.class) { /* code here */ }
    • F、void go() {Object o = new Object();synchronized(o) { /* code here */ }

    正确答案:C,E,F

  • 第8题:

    单选题
    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?()
    A

     Base

    B

     BaseBase

    C

     Compilation fails.

    D

     The code runs with no output.

    E

     An exception is thrown at runtime.


    正确答案: A
    解析: 暂无解析

  • 第9题:

    多选题
    Which two allow the class Thing to be instantiated using new Thing()?
    A

    public class Thing { }

    B

    public class Thing { public Thing() {} }

    C

    public class Thing { public Thing(void) {} }

    D

    public class Thing { public Thing(String s) {} }

    E

    public class Thing { public void Thing() {} public Thing(String s) {} }


    正确答案: E,A
    解析: 暂无解析

  • 第10题:

    单选题
    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?()
    A

     Alpha a = x;

    B

     Foo f= (Delta)x;

    C

     Foo f= (Alpha)x;

    D

     Beta b = (Beta)(Alpha)x;


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    现有:   1.  class Alpha { void m1() {} }   2.  class Beta extends Alpha { void m2() { } }   3.  class Gamma extends Beta { }   4.   5.  class GreekTest {   6.    public static void main(String [] args) {   7.      Alpha [] a = {new Alpha(), new Beta(), new Gamma() };   8.      for(Alpha a2 : a) {   9.        a2.m1();    10.       if (a2 instanceof Beta || a2 instanceof Gamma)    11.         //insert code here   12.     }    13.   }   14. }    哪一行代码插入到第11行,将编译但是会在运行时产生异常?()
    A

     a2.m2();

    B

     ((Beta)a2).m2();

    C

     ((Alpha)a2).m2();

    D

     ((Gamma)a2).m2();


    正确答案: B
    解析: 暂无解析

  • 第12题:

    单选题
    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?()
    A

     new Animal().soundOff();

    B

     Elephant e = new Alpha1();

    C

     Lion 1 = Alpha.get(“meat eater”);

    D

     new Alpha1().get(“veggie”).soundOff();


    正确答案: D
    解析: 暂无解析

  • 第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


    正确答案:C
    解析: 本题考查类的继承、类的实例化和构造函数、析构函数的调用方式和何时调用。每实例化一个类就要调用其构造函数,结束运行该实例后调用析构函数。

  • 第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?() 

    • A、 Line 4 of class Target can be changed to return i++;
    • B、 Line 2 of class Target can be changed to private int i = 1;
    • C、 Line 3 of class Target can be changed to private int addOne() {
    • D、 Line 2 of class Target can be changed to private Integer i = 0;

    正确答案:D

  • 第15题:

    Which two allow the class Thing to be instantiated using new Thing()?

    • A、 public class Thing { }
    • B、 public class Thing { public Thing() {} }
    • C、 public class Thing { public Thing(void) {} }
    • D、 public class Thing { public Thing(String s) {} }
    • E、 public class Thing { public void Thing() {} public Thing(String s) {} }

    正确答案:A,B

  • 第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?()

    • A、 public void aMethod() {}
    • B、 private void aMethod() {}
    • C、 public void aMethod(String s) {}
    • D、 private Y aMethod() { return null; }
    • E、 public X aMethod() { return new Y(); }

    正确答案:C,E

  • 第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?()  

    • A、 Tested
    • B、 Compilation fails.
    • C、 The code runs with no output.
    • D、 An exception is thrown at runtime.

    正确答案:B

  • 第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?()  

    • A、 There are no instanced of A that will become eligible for garbage collection.
    • B、 Explicitly setting myA to null marks that instance to be eligible for garbage collection.
    • C、 Any call on tryIt() causes the private instance of A to be marked for garbage collection.
    • D、 Private instances of A become eligible for garbage collection when instances of Alpha become eligible for garbage collection.

    正确答案:B,D

  • 第19题:

    多选题
    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 */ } }


    正确答案: B,E
    解析: 暂无解析

  • 第20题:

    单选题
    现有:  class Tree {  private static String tree = "tree ";  String getTree ()  {  return tree;  }       }  class Elm extends Tree {  private static String tree = "elm ";  public static void main (String  []  args)  {       new Elm() .go (new Tree())  ;      } }  void go (Tree t)  {  String  s =  t.getTree () +Elm.tree  +  tree  +   (new  Elm() .getTree ()) ;      System.out.println (s) ;}     结果为:()
    A

     elm elm elm elm

    B

     tree elm elm elm

    C

     tree elm elm tree

    D

     tree elm tree elm


    正确答案: D
    解析: 暂无解析

  • 第21题:

    单选题
    1. import java.util.*;  2. class SubGen {  3. public static void main(String [] args) {  4. //insert code here  5. }  6. }  class Alpha { }  class Beta extends Alpha { }  class Gamma extends Beta { }  和四段代码片段:  s1. ArrayList〈? extends Alpha〉 list1 = new ArrayList〈Gamma〉();  s2. ArrayList〈Alpha〉 list2 = new ArrayList〈? extends Alpha〉();  s3. ArrayList〈? extends Alpha〉 list3 = new ArrayList〈? extends Beta〉();  s4. ArrayList〈? extends Beta〉 list4 = new ArrayList〈Gamma〉(); ArrayList〈? extends Alpha〉 list5 = list4;  哪些片段分别插入到第4行,可允许代码编译?()
    A

    只有s1

    B

    只有s3

    C

    只有s1和s3

    D

    只有s1和s4


    正确答案: C
    解析: 暂无解析

  • 第22题:

    单选题
    final class Tree {  private static String tree = "tree ";  String getTree() { return tree; }  }  class Elm extends Tree {  private static String tree = "elm "; public static void main(String [] args) {  new Elm().go(new Tree());  }  void go(Tree t) {  String s = t.getTree()+Elm.tree+tree+(new Elm().getTree());  System.out.println(s);  } }  结果为:()
    A

    elm elm elm elm

    B

    tree elm elm elm

    C

    tree elm tree elm

    D

    编译失败


    正确答案: C
    解析: 暂无解析

  • 第23题:

    单选题
    1. class Alpha { void m1() {} }   2. class Beta extends Alpha { void m2() { } }   3. class Gamma extends Beta { }   4.   5. class GreekTest {   6. public static void main(String [] args) {   7. a Alpha [] a = {new Alpha(), new Beta(), new Gamma() };   8. for(Alpha a2 : a) {   9. a2.m1();   10. if (a2 instanceof Beta || a2 instanceof Gamma)   11. //insert code here   12. }   13. }   14. }   哪一行代码插入到第11行,将编译但是会在运行时产生异常?()
    A

     a2.m2();

    B

     ((Beta)a2).m2();

    C

     ((Alpha)a2).m2();

    D

     ((Gamma)a2).m2();


    正确答案: C
    解析: 暂无解析