自用 | bb选择题 assgn1(chapter09 对象和类)

问题 1

Analyze the following code.

public class Test {
  int x;
 
  public Test(String t) {
     System.out.println("Test");
  }
 
  public static void main(String[] args) {
    Test test = new Test();
    System.out.println(test.x);
  }
}

A.The program has a compile error because x has not been initialized.               

B.The program has a compile error because you cannot create an object from the class that defines the object.

C.The program has a compile error because Test does not have a default constructor.

D.The program has a compile error because System.out.println method cannot be invoked from the constructor.

问题2

The java.util.Date class is introduced in this section. Analyze the following code and choose the best answer:

Which of the following code in A or B, or both creates an object of the Date class:

A:
 

public class Test {
  public Test() {
    new java.util.Date();
  }
}

B:

public class Test {
  public Test() {
    java.util.Date date = new java.util.Date();
  }
}

A.A.

B.Neither

C.B.

问题 3

 What code may be filled in the blank without causing syntax or runtime errors:

public class Test {
  java.util.Date date;
 
  public static void main(String[] args) {
    Test test = new Test();
    System.out.println(_________________);
  }
}

A.test.date

B.test.date.toString()

C.date.toString()

D.date

问题 4

 What is the output of the following program?

import java.util.Date;
public class Test {
  public static void main(String[] args) {
    Date date = new Date(1234567);
    m1(date);
    System.out.print(date.getTime() + " ");
    m2(date);
    System.out.println(date.getTime());
  }
  public static void m1(Date date) {
    date = new Date(7654321);
  }
  public s
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值