5. class Passer3 {   6. final static Passer3 p2 = new Passer

题目
单选题
5. class Passer3 {   6. final static Passer3 p2 = new Passer3();   7. public static void main(String [] args) {   8. Passer3 p4 = p2.go(p2);   9. Passer3 p3 = p2;   10. System.out.print(p3==p4);   11. }   12. Passer3 go(Passer3 p) {   13. p = new Passer3();   14. return p;   15. }   16. }   结果为:()
A

true

B

false

C

第 8 行出现一个错误,编译失败

D

第 9 行出现一个错误,编译失败

参考答案和解析
正确答案: B
解析: 暂无解析
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。

[题目要求]

生成下面左边图形界面,单击图中的New按钮,弹出如右图所示的对话框。

源程序:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Java_3 {

public static void main(String[] args) {

MulticastFrame. frame=new MulticastFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.show();

}

}

class MulticastFrame. extends JFrame. {

public MulticastFrame() {

setTitle("MulticastTest");

setSize(WIDTH,HEIGHT);

MulticastPanel panel=new MulticastPanel();

Container contentPane=getContentPane();

contentPane.add( (1) );

}

public static final int WIDTH=300;

public static final int HEIGHT=200;

}

class MulticastPanel extends JPanel }

public MulticastPanel() {

JButton newButton=new JButton("New");

add(newButton);

ActionListener newListener=new ActionListener() {

public void actionPerformed(ActionEvent event) {

makeNewFrame();

}

};

newButton.addActionListener(newListener);

closeAllButton=new JButton("Close all");

add(closeAllButton);

}

private void makeNewFrame() {

final BlankFrame. frame=new BlankFrame();

frame.show();

ActionListener closeAllListener=new ActionListener() {

public void actionPerformed(ActionEvent event) {

frame. (2) (); //使窗口隐藏或消除

}

};

closeAllButton.addActionListener( (3) );

}

private JButton closeAllButton;

}

Class BlankFrame. extends JFrame. {

public BlankFrame() {

(4) ++;

setTitle("Frame"+counter);

setSize(WIDTH,HEIGHT);

setLocation(SPACING*counter,SPACING*counter);

}

public static final int WIDTH=200;

public static final int HEIGHT=150;

public static final int SPACING=30;

private static int counter=0;

}


正确答案:panel hide closeAllListener counter
panel hide closeAllListener counter 解析: 通过下面的程序可以看出新的窗口的标题为Frame和数字,数字是自增的,所以自增的变量名称为counter。
[程序解析] 程序在窗口中用按钮新建窗口,并且可以通过按钮关闭窗口。本程序采用的是swing类,Swing构件和AWT构件不同,Swing构件不能直接添加到顶层容器中,它必须添加到一个Swing顶层容器相关联的内容面板上。对JFrame添加构件有两种方式:①用getContentPane()方法获得JFrame的内容面板,再对其加入构件,Java上机考试中经常采用这种方式,而且也是一个考点。本程序就是采用的这种方法。②建立一个JPanel或JDesktopPane之类的中间容器,把构件添加到容器中,再用setContentPane()方法把该容器置为JFrame的内容面板。

第2题:

5. class Passer3 {   6. final static Passer3 p2 = new Passer3();   7. public static void main(String [] args) {   8. Passer3 p4 = p2.go(p2);   9. Passer3 p3 = p2;   10. System.out.print(p3==p4);   11. }   12. Passer3 go(Passer3 p) {   13. p = new Passer3();   14. return p;   15. }   16. }   结果为:()      

  • A、true
  • B、false
  • C、第 8 行出现一个错误,编译失败
  • D、第 9 行出现一个错误,编译失败

正确答案:B

第3题:

Which two code fragments correctly create and initialize a static array of int elements()

A.static final int[]a={100,200};

B.static final int[]a;static{a=new int[2];a[0]=100;a[1]=200;}

C.static final int[]a=new int[2]{100,200};

D.static final int[]a;static void int(){a=new int[3];a[0]=100;a[1]=200;}


参考答案:A, B

第4题:

1. public class A {  2. void A() {  3. System.out.println(“Class A”);  4. }  5. public static void main(String[] args) {  6. new A();  7. }  8. }  What is the result?()  

  • A、 Class A
  • B、 Compilation fails.
  • C、 An exception is thrown at line 2.
  • D、 An exception is thrown at line 6.
  • E、 The code executes with no output.

正确答案:E

第5题:

Which declaration prevents creating a subclass of an outer class?()

  • A、 Static class FooBar{}
  • B、 Private class FooBar{}
  • C、 Abstract public class FooBar{}
  • D、 Final public class FooBar{}
  • E、 Final abstract class FooBar{}

正确答案:D

第6题:

1. public class Outer{  2. public void someOuterMethod() {  3. // Line 3  4. }  5. public class Inner{}  6. public static void main( String[]argv ) {  7. Outer o = new Outer();  8. // Line 8  9. }  10. }  Which instantiates an instance of Inner?()  

  • A、 new Inner(); // At line 3
  • B、 new Inner(); // At line 8
  • C、 new o.Inner(); // At line 8
  • D、 new Outer.Inner(); // At line 8

正确答案:A

第7题:

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

第8题:

public class Something {

public static void main(String[] args) {

Other o = new Other();

new Something().addOne(o);

}

public void addOne(final Other o) {

o.i++;

}

}

class Other {

public int i;

}

和上面的很相似,都是关于final 的问题,这有错吗?


正确答案:

 

正确。在addOne method 中,参数o 被修饰成final。如果在addOne method 里我们修

改了o 的reference

(比如: o = new Other();),那么如同上例这题也是错的。但这里修改的是o 的member vairable

(成员变量),而o 的reference 并没有改变。

第9题:

public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO);  System.out.print(((Base)s).FOO);  } }  class Sub extends Base {public static final String FOO=bar;}  What is the result?() 

  • A、 foofoofoofoofoo
  • B、 foobarfoobarbar
  • C、 foobarfoofoofoo
  • D、 foobarfoobarfoo
  • E、 barbarbarbarbar
  • F、 foofoofoobarbar
  • G、 foofoofoobarfoo

正确答案:D

第10题:

现有: 1.class Passer f 2.static final int X=5; 3.public static void main (String [] args) { 4.new Passer( ).go (x); 5.System. out .print (x); 6. ) 7.void go (int x) { 8.System. out .print(x++); 9.} 10.}结果是什么?()

  • A、55
  • B、56
  • C、65
  • D、66

正确答案:A

更多相关问题