← Java Bronze 备考练习 · 题库总览

Java Bronze 全真模拟卷

60 题 · 65 分钟 · 满分 100 分 · 60 分及格

题型与真实机考一致:单选、判断与多选混编。题库为公开的 Sun/Oracle 认证真题,选项已打散顺序,每题附中英日三语解析。

点「开始模考」进入 65 分钟计时,期间隐藏对错与解析;交卷后按百分制给出得分与及格判定。
已答 0/60正确 0错误 0正确率 —
Question 1单选字符串

What will be the output of the below code snippet?

下面这段代码的输出是什么?

次のコードの出力はどれか。

String s1 = "Hello";
String s2 = "John";
System.out.println(s1.concat(s2));
  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 C

concat() returns a new string with the argument appended; it does not modify s1. So the call prints HelloJohn.

concat() 会返回一个把参数拼接到末尾的新字符串,并不会修改 s1。因此输出 HelloJohn。

concat() は引数を連結した新しい文字列を返すだけで、s1 自体は変更しない。よって出力は HelloJohn。

Question 2单选字符串

What will be the output of the below code snippet?

下面这段代码的输出是什么?

次のコードの出力はどれか。

StringBuffer sb = new StringBuffer();
sb.append("Hi");
sb.append("John");
System.out.println(sb.length());
  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

The buffer starts empty and receives "Hi" (2 characters) then "John" (4 more), so length() reports 6.

缓冲区初始为空,先追加 "Hi"(2 个字符)再追加 "John"(4 个字符),所以 length() 返回 6。

バッファは空の状態から "Hi"(2 文字)と "John"(4 文字)を順に追加するため、length() は 6 を返す。

Question 3判断字符串

String class in Java is immutable.

Java 中 String 类是不可变的。这句话是什么意思?

Java の String クラスは不変(immutable)である。この文の意味はどれか。

  1. A
  2. B
解析 / Explanation

正确答案 B

Immutable means that once a String object exists its content never changes. Any method that appears to modify it actually returns a brand-new object.

不可变指的是 String 对象一旦创建,其内容就不会再改变。任何看起来在修改它的方法,实际上都是返回了一个全新的对象。

不変とは、一度生成された String オブジェクトの内容が決して変化しないことを指す。変更しているように見えるメソッドも、実際には新しいオブジェクトを返している。

Question 4多选字符串

Which of the following are valid string functions?

下列哪些是有效的 String 方法?(多选)

有効な String のメソッドはどれか。(すべて選択)

  1. A
  2. B
  3. C
  4. D
  5. E
解析 / Explanation

正确答案 A,B,E

isBlank(), isEmpty() and length() all exist on String. concatenate() is not a String method (the real one is concat()), and size() belongs to collections such as List and Map, not to String.

isBlank()、isEmpty()、length() 都是 String 上真实存在的方法。concatenate() 并不存在(真正的是 concat());size() 属于 List、Map 这类集合,String 没有这个方法。

isBlank()・isEmpty()・length() はいずれも String に存在するメソッド。concatenate() は存在せず(正しくは concat())、size() は List や Map といったコレクションのもので String にはない。

Question 5单选字符串

Which of the following string initialization is correct?

下列哪种 String 初始化写法是正确的?

次のうち正しい String の初期化はどれか。

1. String teststr = "test";
2. String teststr2 = new String ("test2");
  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

Both forms compile and run. The literal form uses the string pool while new String() creates a separate heap object, but both are valid initialisation.

两种写法都能编译运行。字面量写法使用字符串常量池,new String() 则在堆上另建对象——但两种都是合法的初始化。

どちらの書き方もコンパイル・実行できる。リテラル形式は文字列プールを使い、new String() はヒープに別オブジェクトを作るが、どちらも正しい初期化。

Question 6单选字符串

What will be the output of the below code snippet?

下面这段代码的输出是什么?

次のコードの出力はどれか。

String s1 = "Hello";
String s2 = "John";
System.out.println(s1.equals(s2));
  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 C

equals() compares the contents of the two strings. "Hello" and "John" differ, so it returns false.

equals() 比较的是两个字符串的内容。"Hello" 与 "John" 内容不同,所以返回 false。

equals() は 2 つの文字列の内容を比較する。"Hello" と "John" は内容が異なるため false を返す。

Question 7单选字符串

What will be the output of the below code snippet?

下面这段代码的输出是什么?

次のコードの出力はどれか。

String teststr = "testing";
char[] arr=teststr.toCharArray();
for(int p=arr.length-1;p>=0;p--) {
System.out.print(arr[p]);
}
  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 A

The loop walks the character array from the last index down to 0, so it prints the string backwards: gnitset.

循环从字符数组的最后一个下标一路递减到 0,因此把字符串倒序打印出来:gnitset。

ループは文字配列の最後の添字から 0 まで逆順にたどるため、文字列を逆順に出力する:gnitset。

Question 8单选字符串

Select the correct output of the below code snippet:

下面这段代码的输出是什么?

次のコードの出力はどれか。

String str = "Hi";
str.concat("John");
System.out.println(str.length());
  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 C

concat() does not change the original string, and here the returned value is discarded. str is still "Hi", so length() is 2.

concat() 不会改变原字符串,而这里连返回值都被丢弃了。str 依然是 "Hi",所以 length() 为 2。

concat() は元の文字列を変更せず、ここでは戻り値も捨てられている。str は "Hi" のままなので length() は 2。

Question 9单选字符串

Select the correct output of the below code snippet:

下面这段代码的输出是什么?

次のコードの出力はどれか。

String[] strArr = {"hi","john","how","are", "you"};
System.out.println(strArr.length);
  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 A

Arrays expose their size through the length field (no parentheses). The array holds five elements, so it prints 5.

数组通过 length 字段暴露长度(不带括号)。这里数组有 5 个元素,所以输出 5。

配列の長さは length フィールドで参照する(括弧は付けない)。要素は 5 つなので 5 が出力される。

Question 10单选字符串

Which of the following methods is used to find the length of a String in Java?

Java 中用哪个方法获取字符串的长度?

Java で文字列の長さを得るメソッドはどれか。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 B

String.length() returns the number of characters. size() is for collections, and getLength()/StringLength() do not exist.

String.length() 返回字符个数。size() 是集合用的,getLength() 和 StringLength() 根本不存在。

String.length() が文字数を返す。size() はコレクション用で、getLength() や StringLength() は存在しない。

Question 11单选字符串

Which of the following is not a valid string function in Java?

下列哪个不是 Java 中有效的 String 方法?

Java の String メソッドとして存在しないものはどれか。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

String has length(), intern() and (since Java 9) chars(). size() is the odd one out — it belongs to the collection framework.

String 有 length()、intern(),以及 Java 9 起提供的 chars()。只有 size() 不属于 String——它是集合框架的方法。

String には length()・intern()、そして Java 9 以降は chars() がある。size() だけは String のものではなく、コレクションフレームワークに属する。

Question 12单选字符串

Which method removes whitespace from the beginning and end of a String in Java?

Java 中哪个方法会去掉字符串首尾的空白?

文字列の前後の空白を除去するメソッドはどれか。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 B

trim() strips leading and trailing whitespace and is the classic answer here. removeWhiteSpace() and delete() do not exist on String.

trim() 会去掉首尾空白,是这类题的标准答案。removeWhiteSpace() 和 delete() 在 String 上都不存在。

trim() は前後の空白を除去する。removeWhiteSpace() と delete() は String に存在しない。

Question 13单选字符串

Select the correct output of the below code snippet:

下面这段代码的输出是什么?

次のコードの出力はどれか。

String str7 = "orange";
String str8 = "orange";
System.out.println(str7 == str8);
  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

Two identical string literals point at the same interned object, so == compares the same reference and prints true. Contrast this with the next question, which uses new String().

两个完全相同的字符串字面量指向同一个常量池对象,所以 == 比较的是同一个引用,输出 true。可以与下一题对比——那题用了 new String()。

同一の文字列リテラルは同じプール内オブジェクトを指すため、== は同じ参照を比較し true を出力する。new String() を使う次の問題と対比するとよい。

Question 14单选字符串

Select the correct output of the below code snippet:

下面这段代码的输出是什么?

次のコードの出力はどれか。

String str7 = "orange";
String str8 = new String("orange");
System.out.println(str7 == str8);
  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 A

new String() always builds a fresh heap object, so str8 is not the pooled instance str7 refers to. == compares references, not contents, and prints false.

new String() 一定会在堆上新建对象,所以 str8 与 str7 指向的常量池实例不是同一个。== 比较的是引用而非内容,输出 false。

new String() は常にヒープに新しいオブジェクトを作るため、str8 は str7 が指すプール内のインスタンスではない。== は参照を比較するので false が出力される。

Question 15单选异常处理

If exception condition is not handled explicitly in a java program, then in case of occurrence of an exception,

如果程序中未显式处理异常,那么异常发生时由谁处理?

例外が明示的に処理されない場合、発生時にどのように処理されるか。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 A

An uncaught exception is handed to the default handler of the thread it was thrown in — for a plain application that is the main thread, which prints a stack trace and terminates the program.

未捕获的异常会交给抛出它的那个线程的默认异常处理器。对于普通应用程序,也就是 main 线程——它会打印堆栈跟踪并结束程序。

捕捉されなかった例外は、それを投げたスレッドの既定の例外ハンドラに渡される。通常のアプリケーションでは main スレッドが該当し、スタックトレースを出力してプログラムを終了する。

Question 16单选异常处理

A checked exception is the one that:

受检异常(checked exception)是……

検査例外(checked exception)とはどのようなものか。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 A

A checked exception must be handled explicitly: either caught in a try/catch or declared in the method signature with throws. Unchecked exceptions carry no such obligation.

受检异常必须被显式处理:要么用 try/catch 捕获,要么在方法签名上用 throws 声明。非受检异常没有这个义务。

検査例外は明示的な処理が必須で、try/catch で捕捉するか、throws でメソッド宣言に記す必要がある。非検査例外にはその義務がない。

Question 17判断异常处理

'finally' block will never execute if the 'catch' block is missing

如果缺少 catch 块,finally 块就永远不会执行。

catch ブロックがなければ finally ブロックは決して実行されない。

  1. A
  2. B
解析 / Explanation

正确答案 B

False. try-finally without any catch is perfectly legal, and the finally block runs whether or not an exception is thrown.

错误。try-finally 不写 catch 完全合法,而且无论是否发生异常,finally 块都会执行。

誤り。catch を伴わない try-finally は合法であり、例外の有無にかかわらず finally は実行される。

Question 18判断异常处理

A 'try' block can have multiple 'catch' blocks

一个 try 块可以有多个 catch 块。

1 つの try ブロックに複数の catch ブロックを置ける。

  1. A
  2. B
解析 / Explanation

正确答案 B

True. Several catch clauses can follow one try, each handling a different exception type — that is the standard way to handle multiple failure modes.

正确。一个 try 后面可以跟多个 catch 子句,各自处理不同的异常类型——这正是处理多种失败情况的标准写法。

正しい。1 つの try に複数の catch 句を続け、それぞれ別の例外型を処理できる。複数の失敗パターンに対処する標準的な書き方。

Question 19判断异常处理

A 'try' block can have multiple 'finally' blocks?

一个 try 块可以有多个 finally 块吗?

1 つの try ブロックに複数の finally ブロックを置けるか。

  1. A
  2. B
解析 / Explanation

正确答案 B

False. A try may be followed by at most one finally block; that single block is guaranteed to run in either case.

错误。一个 try 后面最多只能有一个 finally 块,它保证无论哪种情况都会执行。

誤り。try の後に置ける finally は最大 1 つで、どちらの場合でも必ず実行される。

Question 20判断异常处理

'catch' and 'finally' both blocks are necessary following the 'try' block

try 块之后必须同时有 catch 和 finally 两个块。

try ブロックの後には catch と finally の両方が必須である。

  1. A
  2. B
解析 / Explanation

正确答案 A

False. You need at least one of them, never both by requirement: try-catch, try-finally and try-catch-finally are all legal.

错误。两者至少要有其一,但从不需要同时具备:try-catch、try-finally、try-catch-finally 都合法。

誤り。少なくとも一方が必要なだけで、両方が必須ではない。try-catch・try-finally・try-catch-finally はいずれも合法。

Question 21判断异常处理

'try', 'catch', 'finally' construct can be nested in any other 'try' or 'catch' or 'finally' blocks

try/catch/finally 结构可以嵌套在任意的 try、catch 或 finally 块中。

try/catch/finally 構文は、他の try・catch・finally ブロックの内部にネストできる。

  1. A
  2. B
解析 / Explanation

正确答案 B

True. The construct nests freely, which is how you handle an exception that occurs while handling another one.

正确。这套结构可以自由嵌套,处理"处理异常时又发生异常"的情况正是靠它。

正しい。この構文は自由にネストでき、例外処理中に別の例外が起きた場合の対処に使われる。

Question 22判断异常处理

'finally' block will never execute if no exception occurs in the 'try' block

如果 try 块中没有发生异常,finally 块就永远不会执行。

try ブロックで例外が発生しなければ、finally ブロックは決して実行されない。

  1. A
  2. B
解析 / Explanation

正确答案 A

False. finally runs on every exit path — normal completion, exception, even a return statement — which is exactly why it is used for cleanup.

错误。finally 在任何退出路径上都会执行——正常结束、抛异常、甚至遇到 return 语句——这正是它被用来做清理的原因。

誤り。finally はどの終了経路でも実行される —— 正常終了、例外発生、return 文の場合も含む。だからこそ後処理に使われる。

Question 23判断异常处理

'catch' block gets skipped if no exception occurred in the 'try' block

如果 try 块中没有发生异常,catch 块会被跳过。

try ブロックで例外が発生しなければ、catch ブロックはスキップされる。

  1. A
  2. B
解析 / Explanation

正确答案 B

True. catch clauses are only entered to handle a matching thrown exception; with nothing thrown, control passes straight on.

正确。catch 子句只在需要处理匹配的异常时才进入;没有异常抛出时,控制直接往下走。

正しい。catch 句は対応する例外を処理するときだけ実行される。何も投げられなければ、そのまま次へ進む。

Question 24单选异常处理

'throw' keyword is used to _______

throw 关键字用于 ______

throw キーワードの用途は ______。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

throw raises an exception object explicitly at the point it appears. Declaring that a method may let one escape is the job of throws, not throw.

throw 是在它出现的位置显式抛出一个异常对象。声明"方法可能向外抛出异常"是 throws 的职责,不是 throw。

throw はその位置で例外オブジェクトを明示的に投げる。メソッドが例外を外へ送出しうることを宣言するのは throws の役割で、throw ではない。

Question 25单选异常处理

'throws' keyword is used to ______

throws 关键字用于 ______

throws キーワードの用途は ______。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

throws appears in a method signature and tells callers which checked exceptions may propagate out. It does not throw anything by itself.

throws 出现在方法签名中,告诉调用方哪些受检异常可能会向外传播。它本身并不抛出任何异常。

throws はメソッド宣言に記し、どの検査例外が外へ伝播しうるかを呼び出し側に伝える。それ自体は何も投げない。

Question 26单选异常处理

All exceptions in java are derived from ________

Java 中所有异常都派生自 ______

Java のすべての例外の派生元は ______。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

Throwable sits at the root. Error and Exception are its two direct branches, so every throwable object is a Throwable.

Throwable 位于继承体系的根部。Error 和 Exception 是它的两个直接分支,所以一切可抛出的对象都是 Throwable。

Throwable が階層の根にある。Error と Exception はその直下の 2 系統であり、投げられるものはすべて Throwable。

Question 27单选异常处理

Exceptions defined by 'Error' and 'RuntimeException' classes and their subclasses are known as

由 Error 和 RuntimeException 及其子类定义的异常称为 ______

Error と RuntimeException およびそのサブクラスが表す例外は ______ と呼ばれる。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

They are unchecked: the compiler does not force you to catch or declare them. Everything else under Exception is checked.

它们是非受检异常:编译器不会强制你捕获或声明。Exception 之下其余的都是受检异常。

これらは非検査例外で、コンパイラは捕捉や宣言を強制しない。Exception 配下のそれ以外は検査例外となる。

Question 28单选类与对象

A reference variable in Java is _________

Java 中的引用变量是 ______

Java の参照変数とは ______。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 A

A reference variable stores the address of an object rather than the object itself, which is why two references can point at the same instance.

引用变量存放的是对象的地址,而不是对象本身——这也是两个引用能指向同一个实例的原因。

参照変数はオブジェクトそのものではなく、そのアドレスを保持する。だから 2 つの参照が同じインスタンスを指せる。

Question 29单选类与对象

An instance variable in Java is _______

Java 中的实例变量是 ______

Java のインスタンス変数とは ______。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

An instance variable belongs to each object separately: every instance gets its own copy, and it exists as long as that object does.

实例变量属于每一个对象:每个实例都持有自己的一份,其生命周期与对象相同。

インスタンス変数は各オブジェクトに属し、インスタンスごとに独立したコピーを持つ。オブジェクトが存在する間だけ有効。

Question 30单选类与对象

A static variable in Java is _______

Java 中的静态变量是 ______

Java の static 変数とは ______。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 B

A static variable belongs to the class, not to any instance: one copy is shared by every object and it can be reached through the class name.

静态变量属于类而不属于任何实例:所有对象共用同一份,可以通过类名直接访问。

static 変数はクラスに属し、インスタンスには属さない。全オブジェクトで 1 つを共有し、クラス名から参照できる。

Question 31单选类与对象

An anonymous class in Java is _____?

Java 中的匿名类是 _____?

Java の匿名クラスとは _____。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

An anonymous class is an inner class declared and instantiated in one expression without a name — common when implementing a single-method interface on the spot.

匿名类是在一个表达式里同时声明并实例化、且没有名字的内部类——常用于就地实现只有一个方法的接口。

匿名クラスは、名前を持たず 1 つの式の中で宣言とインスタンス化を同時に行う内部クラス。単一メソッドのインターフェースをその場で実装する際によく使う。

Question 32单选类与对象

Garbage collection in Java is _____

Java 中的垃圾回收是 _____

Java のガベージコレクションとは _____。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 A

Garbage collection reclaims the heap memory of objects that are no longer reachable. The JVM decides when, so you never free memory by hand.

垃圾回收负责收回那些已经不可达的对象所占的堆内存。时机由 JVM 决定,因此你不需要手动释放内存。

ガベージコレクションは、到達不能になったオブジェクトのヒープ領域を回収する。実行時期は JVM が決めるため、手動でメモリを解放することはない。

Question 33单选类与对象

Object Finalization in Java is __________

Java 中的对象终结(finalization)是 __________

Java のオブジェクトのファイナライズとは __________。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

finalize() was the last chance for an object to release resources before being collected — a rarely used hook, and deprecated since Java 9.

finalize() 曾是对象在被回收前释放资源的最后机会——这个钩子极少使用,且自 Java 9 起已被弃用。

finalize() は回収前にオブジェクトがリソースを解放する最後の機会だった。ほとんど使われない仕組みで、Java 9 以降は非推奨。

Question 34单选类与对象

A final class in java is _______

Java 中的 final 类是 _______

Java の final クラスとは _______。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 A

final on a class blocks inheritance. It can still be instantiated — that is what abstract classes cannot do.

final 修饰类表示禁止继承。它依然可以被实例化——那是抽象类做不到的事。

final を付けたクラスは継承できない。インスタンス化は可能で、できないのは抽象クラスの方。

Question 35判断类与对象

An abstract class cannot be instantiated:

抽象类不能被实例化。

抽象クラスはインスタンス化できない。

  1. A
  2. B
解析 / Explanation

正确答案 B

True. An abstract class may leave methods unimplemented, so the compiler refuses to create an instance of it directly.

正确。抽象类可能留有没有实现的方法,因此编译器不允许直接创建它的实例。

正しい。抽象クラスは未実装のメソッドを持ちうるため、コンパイラは直接インスタンス化を許さない。

Question 36单选类与对象

System.gc() is a method used to _______

System.gc() 是一个用来 _______ 的方法。

System.gc() は _______ ためのメソッドである。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 A

System.gc() asks the JVM to run garbage collection. It is only a suggestion — the runtime may ignore it.

System.gc() 用于请求 JVM 执行垃圾回收,但这只是一个建议——运行时不一定会照做。

System.gc() は JVM にガベージコレクションの実行を促す。あくまで提案であり、実行時に無視されることもある。

Question 37判断类与对象

An object in java can be referenced by multiple reference variables:

Java 中的一个对象可以被多个引用变量引用。

Java の 1 つのオブジェクトを複数の参照変数から参照できる。

  1. A
  2. B
解析 / Explanation

正确答案 B

True. Assigning one reference to another copies the address, so several variables can name the same object — the source of many aliasing bugs.

正确。把引用赋给另一个变量只是复制了地址,因此多个变量可以指向同一个对象——这也是不少别名 bug 的根源。

正しい。参照の代入はアドレスをコピーするだけなので、複数の変数が同じオブジェクトを指せる。これがエイリアス由来のバグの原因になる。

Question 38单选类与对象

A local class in java is ________

Java 中的局部类是 ________

Java のローカルクラスとは ________。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

A local class is an inner class declared inside a block, typically a method body, and it is visible only within that block.

局部类是声明在某个块(通常是方法体)内部的内部类,只在该块范围内可见。

ローカルクラスはブロック(通常はメソッド本体)の内部で宣言される内部クラスで、そのブロック内でのみ参照できる。

Question 39单选类与对象

An identifier in java is ________

Java 中的标识符(identifier)是 ________

Java の識別子(identifier)とは ________。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

An identifier is simply a name you give to a variable, class, method or package. Keywords are reserved words and cannot be used as identifiers.

标识符就是你给变量、类、方法或包起的名字。关键字是保留字,不能拿来当标识符。

識別子は変数・クラス・メソッド・パッケージに付ける名前のこと。キーワードは予約語であり、識別子には使えない。

Question 40单选类与对象

Which of the following is not a keyword in java ______

下列哪个不是 Java 的关键字 ______

Java のキーワードでないものはどれか ______。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 A

new and void are reserved keywords; identifier is an ordinary term describing names you invent, and is not reserved.

new 和 void 都是保留关键字;identifier 只是一个描述"你自己起的名字"的普通术语,并没有被保留。

new と void は予約されたキーワード。identifier は自分で付ける名前を指す一般用語であり、予約語ではない。

Question 41单选类与对象

Which of the following is Not an Integer data type?

下列哪个不是整数类型?

整数型でないものはどれか。

  1. A
  2. B
  3. C
  4. D
  5. E
解析 / Explanation

正确答案 E

int, long, byte and short are all integral types. double is a floating-point type, so it is the exception.

int、long、byte、short 都是整数类型,只有 double 是浮点类型。

int・long・byte・short はすべて整数型。double だけが浮動小数点型。

Question 42单选类与对象

Object class in java is ____?

Java 中的 Object 类是 ____?

Java の Object クラスとは ____。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 A

Object is the root of the class hierarchy: every class implicitly extends it, which is why any object can be assigned to an Object reference.

Object 是类层次结构的根:每个类都隐式继承它,所以任何对象都能赋给 Object 类型的引用。

Object はクラス階層の根で、すべてのクラスが暗黙にこれを継承する。だから任意のオブジェクトを Object 型の参照に代入できる。

Question 43单选类与对象

Select the correct statement for the lifetime of an instance variable ____

关于实例变量的生命周期,正确的说法是 ____

インスタンス変数の寿命について正しい記述は ____。

  1. A
  2. B
  3. C
解析 / Explanation

正确答案 B

An instance variable lives exactly as long as the object that owns it. Once the object becomes unreachable it can be collected along with its fields.

实例变量的生命周期与持有它的对象完全一致。对象一旦不可达,它连同它的字段就可能被回收。

インスタンス変数の寿命は、それを保持するオブジェクトと同じ。オブジェクトが到達不能になれば、フィールドごと回収されうる。

Question 44单选类与对象

What is the output of the below program:

下面程序的输出是什么?

次のプログラムの出力はどれか。

public class finalTest {
final static int r=9;
public static void main(String[] args) {
r++;
System.out.println(r);
}
}
  1. A
  2. B
  3. C
解析 / Explanation

正确答案 C

r is declared final, so r++ attempts to reassign a constant and the compiler rejects it. A final variable may be read as often as you like, never written twice.

r 被声明为 final,r++ 试图给常量重新赋值,编译器直接拒绝。final 变量可以随意读取,但绝不能再写第二次。

r は final なので、r++ は定数への再代入となりコンパイルエラーになる。final 変数は何度読んでもよいが、二度目の代入はできない。

Question 45单选类与对象

Select the correct console output of the below program:

下面程序的正确控制台输出是?

次のプログラムの正しいコンソール出力はどれか。

public class finalTest {
finalTest func1() {
System.out.println("This is func1");
return new finalTest();
}
String func2() {
return "returning string2";
}
public static void main(String[] args) {
finalTest obj2;
obj2=new finalTest();
System.out.println(obj2.func1().func2());
}
}
  1. A
  2. B
  3. C
  4. D
  5. E
解析 / Explanation

正确答案 E

One of the methods declared in this class is named func2 but the code calls a method whose name does not exist, so the file never compiles.

类中声明的方法名与实际调用的方法名不一致,调用了一个不存在的方法,因此这个文件根本无法编译。

宣言されているメソッド名と呼び出している名前が一致せず、存在しないメソッドを呼んでいるためコンパイルできない。

Question 46判断类与对象

A local variable (belonging to a method, as shown below) must be initialized in the method before it is being used. True or False?

属于方法的局部变量必须在方法中使用前初始化(如下所示)。

メソッドに属するローカル変数は、使用前にメソッド内で初期化しなければならない(以下参照)。

public void func2() {
int var1;
var1=5;
System.out.println(var1);
}
  1. A
  2. B
解析 / Explanation

正确答案 B

True. Unlike fields, local variables receive no default value, so the compiler insists that a value is assigned before any read.

正确。与字段不同,局部变量没有默认值,因此编译器要求任何读取之前必须已经赋值。

正しい。フィールドと違いローカル変数に既定値はないため、読み取り前に代入が必須とコンパイラが要求する。

Question 47判断类与对象

An instance or static variable, if not initialized explicitly, then?

实例变量或静态变量如果没有被显式初始化,会怎样?

インスタンス変数や static 変数を明示的に初期化しないとどうなるか。

  1. A
  2. B
解析 / Explanation

正确答案 A

Fields are always given a default: 0 for numeric primitives, false for boolean, null for references. Only local variables are left uninitialised.

字段总会获得默认值:数值型为 0,boolean 为 false,引用类型为 null。只有局部变量才会处于未初始化状态。

フィールドには必ず既定値が入る。数値は 0、boolean は false、参照型は null。未初期化のままなのはローカル変数だけ。

Question 48单选类与对象

Select the correct output of the below program:

下面程序的正确输出是?

次のプログラムの正しい出力はどれか。

public class finalTest {
int var1;
public void func2() {
System.out.println(var1);
}
public static void main(String[] args) {
finalTest obj2=new finalTest();
obj2.func2();
}
}
  1. A
  2. B
  3. C
解析 / Explanation

正确答案 A

var1 is an instance field, so it defaults to 0 and printing it is legal — no initialisation is required for fields.

var1 是实例字段,默认值为 0,打印它完全合法——字段不需要显式初始化。

var1 はインスタンスフィールドなので既定値 0 を持ち、出力は合法。フィールドに初期化は不要。

Question 49单选类型转换

A type conversion in which the value of a narrower primitive data type is converted to a value of a broader primitive data type is called ________

把较窄的原始数据类型的值转换成较宽类型的值的类型转换称为 ______

狭いプリミティブ型の値を広いプリミティブ型へ変換することを ______ と呼ぶ。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

Widening primitive conversion. Going from a smaller to a larger type never loses information, so no cast is needed.

这是拓宽原始类型转换。从小类型转到大类型不会丢失信息,因此不需要强制转型。

拡大プリミティブ変換。小さい型から大きい型への変換では情報が失われないため、キャストは不要。

Question 50单选类型转换

A type conversion in which a broader primitive datatype is assigned to a narrower (smaller) data type is called ________

把较宽的原始数据类型赋给较窄(较小)类型的转换称为 ______

広いプリミティブ型をより狭い型へ代入する変換を ______ と呼ぶ。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

Narrowing primitive conversion. It can lose information, so the compiler demands an explicit cast.

这是窄化原始类型转换。它可能丢失信息,所以编译器要求显式强制转型。

縮小プリミティブ変換。情報が失われる可能性があるため、明示的なキャストが必要。

Question 51单选类型转换

Assigning an int data type to a double data type will be considered as ________

把 int 类型赋给 double 类型属于 ________

int 型を double 型へ代入するのは ________ に当たる。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

int to double is a widening primitive conversion: double has a wider range, so the assignment happens silently.

int 转 double 属于拓宽原始类型转换:double 的范围更大,所以赋值会自动完成。

int から double は拡大プリミティブ変換。double の方が範囲が広いため、代入は暗黙に行われる。

Question 52单选类型转换

Assigning a double type of data to an int type will be considered as _________

把 double 类型赋给 int 类型属于 _________

double 型を int 型へ代入するのは _________ に当たる。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

Narrowing primitive conversion: the fractional part would be discarded, so an explicit cast is required.

窄化原始类型转换:小数部分会被丢弃,因此必须写显式强制转型。

縮小プリミティブ変換。小数部が切り捨てられるため、明示的なキャストが必須。

Question 53单选类型转换

The conversions between reference types where super type gets converted to subtype are called _______

引用类型之间,把父类型转换成子类型的转换称为 ______

参照型どうしで、スーパー型をサブ型へ変換することを ______ と呼ぶ。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

Narrowing reference conversion, known as downcasting. The compiler allows it only with a cast, and the JVM checks the real object type at runtime.

这是窄化引用转换,也就是向下转型。编译器只允许在写强制转型时通过,而 JVM 会在运行时检查对象的真实类型。

縮小参照変換、いわゆるダウンキャスト。キャストを書いた場合のみコンパイルが通り、実行時に JVM が実際の型を検査する。

Question 54判断类型转换

Casting between a primitive data type and a reference type is not permitted in Java.

在 Java 中,原始类型和引用类型之间不允许互相转换。

Java では、プリミティブ型と参照型の間でキャストは許されない。

  1. A
  2. B
解析 / Explanation

正确答案 B

True. The two type systems are separate; you cannot cast an int to a String or an object to a primitive.

正确。两套类型系统彼此独立,不能把 int 转成 String,也不能把对象转成原始类型。

正しい。2 つの型体系は別系統であり、int を String に、オブジェクトをプリミティブにキャストすることはできない。

Question 55判断类型转换

Boolean values can also be cast to other data values and vice versa:

boolean 值可以转换(cast)成其他数据类型的值,反之亦然。

boolean 値は他のデータ型へキャストでき、その逆もできる。

  1. A
  2. B
解析 / Explanation

正确答案 B

False. boolean is not convertible to or from any numeric type in Java — not even with a cast.

错误。在 Java 中 boolean 不能与任何数值类型互相转换——即使写强制转型也不行。

誤り。Java では boolean をいかなる数値型とも相互変換できない。キャストを書いても不可。

Question 56判断类型转换

Assigning a broader datatype to a smaller datatype requires an explicit cast:

把较宽的数据类型赋给较小的数据类型需要显式强制转型。

広いデータ型を狭い型へ代入するには明示的なキャストが必要である。

  1. A
  2. B
解析 / Explanation

正确答案 B

True. Narrowing conversions can lose information, so Java never performs them implicitly.

正确。窄化转换可能丢失信息,因此 Java 从不隐式执行它。

正しい。縮小変換は情報が失われうるため、Java が暗黙に行うことはない。

Question 57单选访问修饰符

The private member of a class can be accessible

类的 private 成员可以在哪里访问?

クラスの private メンバにはどこからアクセスできるか。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 A

private is the most restrictive modifier: the member is visible only inside the class that declares it — not to subclasses, not to the same package.

private 是最严格的修饰符:成员只在声明它的类内部可见——子类不行,同一个包里的其他类也不行。

private は最も制限の強い修飾子で、宣言したクラスの内部からのみ参照できる。サブクラスからも同一パッケージからも不可。

Question 58单选访问修饰符

The protected member of a class can be accessible

类的 protected 成员可以在哪里访问?

クラスの protected メンバにはどこからアクセスできるか。

  1. A
  2. B
  3. C
  4. D
  5. E
解析 / Explanation

正确答案 D

protected combines package access with inheritance: classes in the same package plus subclasses anywhere. That is options A and B together.

protected 兼具包内访问和继承访问:同包的类,以及任意位置(哪怕不同包)的子类。也就是选项 A 与 B 的合并。

protected はパッケージ内アクセスと継承アクセスを兼ねる。同一パッケージのクラスに加え、どこにあるサブクラスからも参照できる。つまり A と B の両方。

Question 59单选访问修饰符

The public member of a class can be accessible

类的 public 成员可以在哪里访问?

クラスの public メンバにはどこからアクセスできるか。

  1. A
  2. B
  3. C
  4. D
解析 / Explanation

正确答案 D

public imposes no restriction at all: the declaring class, its package, other packages, subclasses — everywhere.

public 不施加任何限制:声明它的类、同包、其他包、子类——处处可访问。

public は一切の制限を課さない。宣言したクラス・同一パッケージ・他パッケージ・サブクラス、どこからでも参照できる。

Question 60单选访问修饰符

The default member of a class (with no explicit member accessibility modifier) can be accessible

类的默认成员(没有写任何访问修饰符)可以在哪里访问?

クラスの既定メンバ(アクセス修飾子を何も書かない場合)にはどこからアクセスできるか。

  1. A
  2. B
  3. C
  4. D
  5. E
解析 / Explanation

正确答案 B

No modifier means package-private: visible to every class in the same package, to nobody outside it.

不写修饰符就是包级私有:同包的所有类都能访问,包外一律不行。

修飾子を書かない場合はパッケージプライベートとなり、同一パッケージの全クラスから参照でき、外からは参照できない。

答题卡 已答 0 · 正确 0 · 错误 0