java工程师信产部认证考试

在Java中,下列代码将输出()。  1.    public class integerequals  2.    {  3.       public static void main (String args[])  4. {  5.  Integer a= new Integer(3);  6.  Integer b= new Integer(3);  7.   System.out.println(a==b);  8. }  9.    } A、编译器将显示第7行有错误B、程序编译并打印tru

题目

在Java中,下列代码将输出()。  1.    public class integerequals  2.    {  3.       public static void main (String args[])  4. {  5.  Integer a= new Integer(3);  6.  Integer b= new Integer(3);  7.   System.out.println(a==b);  8. }  9.    } 

  • A、编译器将显示第7行有错误
  • B、程序编译并打印true
  • C、程序编译并打印false
  • D、程序编译但在第7行引起了一个运行期意外
如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

public static void main(String[]args){Integer i=new Integer(1)+new Integer(2);switch(i){case3:System.out.println("three");break;default:System.out.println("other");break;}}Whatistheresult?()

A.three

B.other

C.Anexceptionisthrownatruntime.

D.Compilationfailsbecauseofanerroronline12.

E.Compilationfailsbecauseofanerroronline13.

F.Compilationfailsbecauseofanerroronline15.


参考答案:A

第2题:

 class Super {  public Integer getLenght() { return new Integer(4); } }  public class Sub extends Super {  public Long GetLenght() { return new Long(5); }  public static void main(String[] args) { Super sooper = new Super();  Sub sub = new Sub();  System.out.println(  sooper.getLenght().toString() + “,” +  sub.getLenght().toString() ); } }  What is the output?()  

  • A、 4,4
  • B、 4,5
  • C、 5,4
  • D、 5,5
  • E、 Compilation fails.

正确答案:A

第3题:

本题中,用表格表现某个月的月历,其中标题是从Sunday到Saturday,表格中的各项是可以修改的。 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class java2 ( public static void main(String[]args) { try{ UIManager.setLookAndFeel(UIManager.getSys- temLookAndFeelClassName): } catch(Exception e) JFrame. frame=new CalendarTableFrame; frame.setDefaultCloseOperation(JFrame.EXIT_ oN CLOSE); frame.show; } } clasgCalendarTableFrame. extends JFrame { private static final int WIDTH=500; private static final int HEIGHT=150: private cells= { {null,null,null,new Integer(1),new Integer (2),new Integer(3),new Integer(4)), {new Integer(5),new Integer(6),new Integer (7).new Integer(8),new Integer(9),new Integer (10),new Integer(11)), {new Integer(12),new Integer(13),new Integer (14),new Integer(15),new Integer(16),new Integer (17),new Integer(18)), {new Integer(19),new Integer(20),new Integer (21),new Integer(22),new Integer(23),new Integer (24),new Integer(25)), {new Integer(26),new Integer(27),new Integer (28),new Integer(29),new Integer(30),new Integer (31),null} }; private String[]columnNames={ "Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday" }; public CalendarTableFrame{ setTitle("java2"); setSize(WIDTH,HEIGHT); JTable table=new ; getContentPane.add(new JScrollPane(table), BorderLayout.CENTER); } }


正确答案:
第1处:Object[][]
第2处:JTable(cells,columnNames)
【解析】第1处定义二维数组保存日期数据;第2处JTable的构造方法第一个参数是数据,第二个参数是表格第一行中显示的内容。

第4题:

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

第5题:

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

第6题:

编译和运行以下代码结果为:

1. public class EqualsTest{

2. public static void main(String args[]){

3. byte A=(byte)4096;

4. if(A== 4096、System.out.println("Equal");

5. else System.out.println("Not Equal");

6. }

7. }

A.在第3行出现转换丢失精度的编译错误.

B.输出 "Not Equal".

C.输出 "Equal".


正确答案:B

第7题:

public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? () 

  • A、 0
  • B、 3
  • C、 Compilation fails.
  • D、 An exception is thrown at runtime.

正确答案:A

第8题:

下列程序中,实现将封装数据类型Integer和基本数据类型int之间的转换,以及Integer,int类型和String类型之间的转换。请将程序补充完整。

程序运行结果如下:

123

456

456

public class ex7_1{

public static void main(String[]args) {

Integer intObj;

int n;

String s;

intObj = new Integer(123);

n=intObj.__________;

System.out.printin(Integer.toString(n));

s=new String("456");

intObj=Integer._________;

System.out.println(intObj.__________);

n=Integer.parseInt(s);

System.out.println(Integer.toString(n));

}

}


正确答案:intValue() valueOf(s) toString()
intValue() valueOf(s) toString() 解析:本题主要考查Java类库中对简单数据类型的封装以及对封装类型与基本类型之间的转换。解题关键是熟悉基本数据类型的封装,以及一些常用封装类型的常用转换方法,如Integer类的parseInt()方法等。本题中,第1个空,使用intValue()方法将封装对象intObj转换为基本的数据类型int;第2个空,使用valueOf()方法,将字符串转换为封装对象intObj;第3个空,使用toString()方法,将封装对象intObj转换为字符串打印出来,注意,这里不可以加参数。

第9题:

class Beta {  public static void main(String [] args) {  Integer x = new Integer(6) * 7;  if (x != 42) {  System.out.print("42 ");  } else if (x 〈 new Integer(44-1)) {  System.out.println("less");  } else {  System.out.print("done"); } } }  结果是什么?() 

  • A、less
  • B、42
  • C、done
  • D、编译失败

正确答案:A

第10题:

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

更多相关问题