java第8章,java第八章

ing constructor in a class, xMethod() is _________ in the class.

public MyClass() {

xMethod();

}

a. an instance method

b. a static method or an instance method

c. a static method

#

17. To declare a constant MAX_LENGTH as a member of the class, you write

a. final double MAX_LENGTH = 99.98;

b. final static double MAX_LENGTH = 99.98;

c. final static MAX_LENGTH = 99.98;

d. static double MAX_LENGTH = 99.98;

e. final static float MAX_LENGTH = 99.98;

#

18. Which of the following statements are true?

a. The default constructor is a no-arg constructor.

b. At least one constructor must always be defined explicitly.

c. A default constructor is provided automatically if no constructors are explicitly declared in the class.

d. Every class has a default constructor.

#

19. You use underline to denote static variables and methods.

a. false

b. true

#

20. You use the plus sign (+) to denote public data or methods.

a. true

b. false

#

21. 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 static void m2(Date date) {

date.setTime(7654321);

}

}

a. 1234567 7654321

b. 7654321 7654321

c. 7654321 1234567

d. 1234567 1234567

#

22. Analyze the following code:

public class Test {

public static void main(String args[]) {

NClass nc = new NClass();

nc.t = nc.t++;

}

}

class NClass {

int t;

private NClass() {

}

}

a. The program has a compilation error because the NClass class has a private constructor.

b. The program compiles, but has a runtime error because t has no initial value.

c. The program compiles and runs fine.

d. The program does not compile because the parameter list of the main method is wrong.

#

23. Which of the following statement is most accurate?

a. A reference variable is an object.

b. An object may contain the references of other objects.

c. A reference variable refers to an object.

d. An object may contain other objects.

#

24. Suppose you wish to provide an accessor method for a boolean property finished, what signature of the method should be?

a. public void getFinished()

b. public boolean isFinished()

c. public void isFinished()

d. public boolean getFinished()

#

25. Suppose TestCircle1 and Circle1 in Listing 8.1 are in two separate files named TestCircle1.java and Circle1.java, respectively. What is the outcome of compiling TestCircle.java and then Circle

.java?

a. Both compile fine.

b. Only TestCircle1.java compiles.

c. Neither compiles successfully.

d. Only Circle1.java compiles.

#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值