1)You can declare two variables with the same name in ________. 1) _______
A)a method one as a formal parameter and the other as a local variable
B)different methods in a class
C)two nested blocks in a method (two nested blocks means one being inside the other)
D)a block

重载函数

2)What is the printout for the second statement in the main method?

public class Foo {
static int i = 0;
static int j = 0;
public static void main(String[ ] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}
k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}

A)k is 0 B) k is 2 C) k is 3 D) k is 1

注意 大括号里的int j = 3是局部变量,离开作用域无效

3)Analyze the following code: (Choose all that apply.)

class Test {
private double i;
public Test(double i) {
this.t();
this.i = i;
}
public Test() {
System.out.println("Default constructor");
this(1);
}
public void t() {
System.out.println("Invoking t");
}
}

A)this.t() may be replaced by t().
B)this(1) must be called before System.out.println("Default constructor").
C)this.i may be replaced by i. //同名需要用this来区别
D)this(1) must be replaced by this(1.0).

4)What is the printout for the first statement in the main method?

public class Foo {
static int i = 0;
static int j = 0;
public static void main(String[ ] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}
k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}

A)i + j is 5 B) i + j is 23 C) i + j is 22 D) i + j is 6

注意这里的输出是字符串,"i + j is " + i + j

5)Analyze the following code:

class Circle {
private double radius;
public Circle(double radius) {
radius = radius;
}
}

A)The program does not compile because Circle does not have a default constructor.
B)The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0.
C)The program has a compilation error because it does not have a main method.
D)The program has a compilation error because you cannot assign radius to radius.

6)What is the printout for the third statement in the main method?

public class Foo {
static int i = 0;
static int j = 0;
public static void main(String[ ] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}
k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}

A)j is 1 B) j is 0 C) j is 3 D) j is 2

7)Which of the following statements are true about an immutable object? (Choose all that apply.)
A)All properties of an immutable object must be of primitive types.
B)All properties of an immutable object must be private.
C)An immutable object contains no mutator methods.
D)The contents of an immutable object cannot be modified.
E)An object type property in an immutable object must also be immutable.

不可变对象的所有属性必须是私有的。
不可变对象不包含任何更改器(mutator)方法。
不可变对象的内容不能修改。
不可变对象中的对象类型属性也必须是不可变的。

8)Which of the following statements are correct? (Choose all that apply.) 1) _______
A)new java.math.BigInteger(343);
B)new java.math.BigDecimal("343.445");
C)new java.math.BigDecimal(343.445);
D)new java.math.BigInteger("343");

new BigDecimal(String)

new BigInteger(String)

9)Which of the following statements will convert a string s into i of int type? (Choose all that apply.) 3) _______
A)i = Integer.valueOf(s);
B)i = Integer.parseInt(s);
C)i = (new Integer(s)).intValue();
D)i = Integer.valueOf(s).intValue();
E)i = (int)(Double.parseDouble(s));

paseInt(s)方法将一个数值字符串s转换为一个int值

inValue()返回包装类对象对应的int值

静态方法valueOf(String s)创建一个新对象,并将t初始化为指定字符串表示的值

10)In JDK 1.5, you may directly assign a primitive data type value to a wrapper object. This is called ________. 5) _______
A)auto conversion B) auto casting C)auto unboxing D) auto boxing

将基本数据类型转换为包装类对象称为装箱(boxing)

将包装类对象转换为基本数据类型对象称为拆箱(unboxing)


基本数据类型和包装类对象之间的转换是自动的(auto)

11)In JDK 1.5, analyze the following code. (Choose all that apply.)
Line 1: Integer[ ] intArray = {1, 2, 3};
Line 2: int i = intArray[0] + intArray[1];
Line 3: int j = i + intArray[2];
Line 4: double d = intArray[0];
A)It is OK to mix an int value with an Integer object in an expression in Line 3.
B)Line 4 is OK. An int value from intArray[0] object is assigned to a double variable d.
C)It is OK to assign 1, 2, 3 to an array of Integer objects in JDK 1.5.
D)It is OK to automatically convert an Integer object to an int value in Line 2.

12)Which statements are most accurate regarding the following classes?

class A {
private int i;
protected int j;
}
class B extends A {
private int k;
protected int m;
}

A)An object of B contains data fields k, m.
B)An object of B contains data fields j, k, m.
C)An object of B contains data fields j, m.
D)An object of B contains data fields i, j, k, m.

私有成员也会被继承,但不能被访问。

13)To divide BigDecimal b1 by b2 and assign the result to b1, you write ________. 17) ______
A)b2.divide(b1);
B)b1 = b2.divide(b1);
C)b1 = b1.divide(b2);
D)b1.divide(b2);
E)b1 = b2.divide(b1);

14)Which of the following statements convert a double value d into a string s? 21) ______
A)s = (new Double(d)).toString();
B)s = String.stringOf(d);
C)s = new Double(d).stringOf();
D)s = (Double.valueOf(s)).toString();

15)Which of the following statements is correct? (Choose all that apply.) 22) ______
A)Integer.parseInt(100);  
B)Integer.parseInt("345", 8);
C)Integer.parseInt(100, 16);  
D)Integer.parseInt("12", 2);
E)Integer.parseInt("100");

parseInt(String s)将一个数值字符串转换从一个int值

16)Which of the following classes are immutable? (Choose all that apply.)  24) ______
A)Double  B)Integer C)String D)BigInteger E)BigDecimal

17)To create an instance of BigDecimal for 454.45, use 25) ______
A)BigInteger("454.45"); B) new BigInteger(454.45);
C)BigInteger(454.45); D) new BigDecimal("454.45");

18)To add BigInteger b1 to b2, you write ________. (Choose all that apply.) 28) ______
A)b2 = b1.add(b2);
B)b2.add(b1);
C)b1 = b2.add(b1);
D)b2 = b2.add(b1);
E)b1.add(b2);

19)Which statements are most accurate regarding the following classes?

class A {
private int i;
protected int j;
}
class B extends A {
private int k;
protected int m;
// some methods omitted
}

A)In the class B, an instance method can only access j, k, m.
B)In the class B, an instance method can only access j, m.
C)In the class B, an instance method can only access i, j, k, m.
D)In the class B, an instance method can only access k, m.

子类只可以访问父类中的非私有成员

20)Analyze the following code.

    Number[ ] numberArray = new Integer[];
numberArray[] = new Double(1.5);

A)Since each element of numberArray is of the Number type, you cannot assign a Double object to it.
B)Since each element of numberArray is of the Number type, you cannot assign an Integer object to it.
C)At
runtime, new Integer[2] is assigned to numberArray. This makes each
element of numberArray an Integer object. So you cannot assign a Double
object to it.

D)You cannot use Number as a data type since it is an abstract class.

21)BigInteger and BigDecimal are immutable 39) ______
A)true B) false

BigInteger 和 BigDecimal都是不可变类

22)Which of the following statements will convert a string s into a double value d? 40) ______
A)d = (new Double(s)).doubleValue();
B)d = Double.valueOf(s).doubleValue();
C)d = Double.parseDouble(s);
D)All of the above.

Java题库——Chapter10 面向对象思考的更多相关文章

  1. Java题库——Chapter13抽象类和接口

    )What is the output of running class Test? public class Test { public static void main(String[ ] arg ...

  2. Java题库——Chapter11 继承和多态

    1)Analyze the following code: public class Test { public static void main(String[ ] args) { B b = ne ...

  3. Java题库——Chapter8 对象和类

    1)________ represents an entity(实体) in the real world that can be distinctly identified. 1) _______ ...

  4. JAVA题库01

    说出一些常用的类,包,接口,请各举5个 常用的类:BufferedReader  BufferedWriter  FileReader  FileWirter  String Integer java ...

  5. Java题库——Chapter17 二进制I/0

    Introduction to Java Programming 的最后一章,完结撒花!Chapter 17 Binary I/O Section 17.2 How is I/O Handled in ...

  6. Java题库——Chapter16 JavaFX UI组件和多媒体

    Chapter 16 JavaFX UI Controls and Multimedia Section 16.2 Labeled and Label1. To create a label with ...

  7. Java题库——Chapter14 JavaFX基础

    Chapter 14 JavaFX Basics Section 14.2 JavaFX vs Swing and AWT1. Why is JavaFX preferred?a. JavaFX is ...

  8. Java题库——Chapter12 异常处理和文本IO

    异常处理 1)What is displayed on the console when running the following program? class Test { public stat ...

  9. Java题库——Chapter9 String的用法

    1)Which code fragment would correctly identify the number of arguments passed via the command line t ...

随机推荐

  1. 《Java基础知识》Java标示符、保留字和数制

    一.Java标识符程序员对程序中的各个元素加以命名时使用的命名记号称为标识符(identifier).Java语言中,标识符是以字母,下划线(_),美元符($)开始的一个字符序列,后面可以跟字母,下划 ...

  2. 曹工说Spring Boot源码(4)-- 我是怎么自定义ApplicationContext,从json文件读取bean definition的?

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享 工程代码地址 思维导图地址 工程结构图: 大 ...

  3. django admin配置以及使用

    admin组件使用 Django 提供了基于 web 的管理工具(django 2.0+, python3.6+). Django 自动管理工具是 django.contrib 的一部分.你可以在项目 ...

  4. 新人踩坑的一天——springboot注入mapper时出现java.lang.NullPointerException: null

    来公司的第二周接到了定时任务的开发需求:每天早上十点发送用户报表邮件 .校招新人菜鸟没做过这玩意有些懵(尴尬)于是决定分步写,从excel导出->邮件发送->定时器实现->mappe ...

  5. JS---变速动画函数封装

    变速动画函数封装 匀速动画:每次步数都是10 (var step=10;) 变速(缓动)动画:每次的步数是用当前位置和目标位置相减 var step=(target-current)/10; 代码如下 ...

  6. 域控权限提升PTH攻击

    0x01 漏洞利用条件 1.被pth攻击的计算机未打补丁(KB2871997)2.拿到一台域成员主机并且拿到管理员组的域用户的NTML 3.对方主机存在相同账号并且是管理员组成员 0x02 本地用户N ...

  7. 如何把Mybatis的Mapper.xml配置文件和dao接口放在同一个包下

    有的时候我们在Maven项目中写关于Mybatis的项目时,会涉及到很多的实体类,也就会涉及到很多的dao接口,如果此时我们仍然把dao接口和xml写在同一个包下,会让项目接口变得很乱,杂七杂八的,所 ...

  8. STM32基本GPIO操作:按键输入(扫描+外部中断)

    (涉及专有名词较多,难免解释不到位,若有错误还请指出,谢谢!) 硬件连接图如下: 一.扫描 思路是在main函数中通过死循环来扫描端口电平状态检测,以此判断按键是否按下.实现较为简单. 1.初始化(注 ...

  9. 微软与阿里云合作推出“开放应用模型(OAM)”

    英文原文:Announcing the Open Application Model (OAM) 原文标题:微软与阿里云合作推出“开放应用模型(OAM)” 用于 Kubernetes 及更多平台的应用 ...

  10. Dynamics 365 Customer Enagement中的更改跟踪(change tracking)

    我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...