問題一覧
1
パッケージに関する説明として、正しいものを選びなさい。(3つ選択) (第一章 簡単なプログラムの作成)
名前空間を提供する, アクセス制御を提供する, クラスの分類を可能にする
2
次のうち、パッケージ宣言が正しく記述されているコードを選びなさい。(1つ選択) (第一章 簡単なプログラムの作成)
package aaa; import java.io.*; public class Sample { }
3
次のうち、インポート宣言しなくても、自動的にインポートされるものはどれか。正しいものを選びなさい。(2つ選択) (第一章 簡単なプログラムの作成)
java.langパッケージに属するクラス, 同じパッケージに属するクラス
4
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) public class Sample { protected int num = 10; } package ex4; public class SampleImpl extends Sample { public static void main(String[ ] args) { System.out.println(num); } } (第一章 簡単なプログラムの作成)
コンパイルエラーが発生する
5
アプリケーションのエントリーポイントとなるメソッドの条件として正しいものを選びなさい。(3つ選択) (第一章 簡単なプログラムの作成)
public であること, staticであること, 引数はString配列型もしくはString型の可変長引数であること
6
次のプログラムを以下に示したコマンドで実行したときの結果として、正しいものを選びなさい。(1つ選択) >java Main java one two public class Main { public static void main(String[] args) { System.out.println(args[0] + " " + args[1]); } } (第一章 簡単なプログラムの作成)
「java one」と表示される
7
次のうち、Javaのクラスを実行するコマンドとして、正しいものを選びなさい。(2つ選択) (第一章 簡単なプログラムの作成)
java Test, java Test.java
8
以下に示したSampleクラスを実行したときの結果として、正しいものを選びなさい。なお、実行時のコマンドは次の通りとする。(1つ選択) > java Sample a ¥” a¥" "a "b c public class Sample { public static void main(String... args) { System.out.println(args.length); } } (第一章 簡単なプログラムの作成)
5が表示される
9
次の説明のうち、正しいものを選びなさい。(2つ選択) (第十一章 モジュールシステム)
モジュールの設定は、module-info.javaに記述する, モジュールの設定では、どのパッケージを公開するかを記述する
10
libディレクトリにあるsampleモジュールを実行したい。 エントリーポイントを持つクラスをcom.test.Helloとしたときのコマンドとして正しいものを選びなさい。(1つ選択) (第十一章 モジュールシステム)
java --module-path lib -m sample/com.test.Hello
11
sampleモジュールは、com.sampleパッケージを公開し、testモジュールを利用している。 module-info.javaの設定として正しいものを選びなさい。(1つ選択) (第十一章 モジュールシステム)
module sample { exports com.sample; requires test; }
12
次のようなモジュールグラフがあったとき、module1でmodule3に属するパッケージのクラスを利用する際の説明として正しいものを選びなさい。(1つ選択) <モジュールグラフ> module1 ↓ module2 ↓ module3 (第十一章 モジュールシステム)
module2のmodule-info.javaで、module3をrequires transitiveで宣言する
13
あらかじめ用意されているモジュールのうち、標準で組み込まれているモジュールとして、正しいものを選びなさい。(1つ選択) (第十一章 モジュールシステム)
java.base
14
module-info.javaに設定したモジュールの設定情報を調べるためのコマンドとして、正しいものを選びなさい。(2つ選択) (第十一章 モジュールシステム)
java --describe-module, jmod describe
15
module-info.javaでexportsされていないパッケージを、一時的に利用してコンパイルしたい。 javacコマンドのオプションとして正しいものを選びなさい。(1つ選択) (第十一章 モジュールシステム)
--add-exports
16
次のプログラムを確認し、Mainクラスの空欄( ? )に入るコードとして、正しいものを選びなさい。(2つ選択) //1~~~~~~~ interface Algorithm { void perform(String name); } //2~~~~~~~ class Service { private Algorithm logic; public void setLogic(Algorithm logic){ this.logic = logic; } public void doProcess(String name){ System.out.println("start"); this.logic.perform(name); System.out.println("end"); } } //3~~~~~~~ public class Main { public static void main(String[] args) { Algorithm algorithm = ( ? ) -> { System.out.println("hello, " + name); }; Service s = new Service(); s.setLogic(algorithm); s.doProcess("Lambda"); } } ~~~~~~ (第八章 関数型インターフェース、ラムダ式)
(name), (String name)
17
次のプログラムの「// insert code here」に入るコードとして、誤っているものを選びなさい。(2つ選択) public class Main { public static void main(String[] args) { 「 // insert code here 」 System.out.println(f.test("Lambda")); } private static interface Function { String test(String name); } } (第八章 関数型インターフェース、ラムダ式)
Function f = (name) -> { "hello, " + name; };, Function f = (name) -> return "hello, " + name;
18
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { String val = "A"; Function f = (val) -> { System.out.println(val); }; f.test("B"); } } interface Function { void test(String val); } ~~~ (第八章 関数型インターフェース、ラムダ式)
コンパイルエラーが発生する
19
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Sample { public static void main(String[] args) { int cnt = 0; Runnable r = () -> { for (cnt = 0; cnt < 10; cnt++) { System.out.println(cnt++); } }; new Thread(r).start(); } } ~~~ (第八章 関数型インターフェース、ラムダ式)
コンパイルエラーが発生する
20
次のプログラムを実行し、「ok」と表示したい。 11行目の空欄「 ? 」に入るコードとして、正しいものを選びなさい。(1つ選択) ~~~ import java.util.Arrays; import java.util.List; import java.util.function.*; public class Main { public static void main(String[] args) { List<Sample> list = Arrays.asList( new Sample(10), new Sample(20), new Sample(30)); 「 ? 」 if (x.test(new Sample(20))){ System.out.println("ok"); } } } class Sample { private int num; public Sample(int num){ this.num = num+ } public boolean equals(Object obj){ if (obj instanceof Sample == false){ return false; } if(this.num == ((Sample) obj).num){ return true; } return false; } } ~~~ (第八章 関数型インターフェース、ラムダ式)
Predicate<Sample> x = s -> list.contains(s);
21
java.util.functionパッケージに属する関数型インターフェースで、引数を受け取らず、結果を戻すためのものを選びなさい。(1つ選択) (第八章 関数型インターフェース、ラムダ式)
Supplier
22
次のプログラムの空欄「 ? 」に入るコードとして、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { 「 ? 」<String, Integer> func = (str) -> { return Integer.parseInt(str); }; } } ~~~ (第八章 関数型インターフェース、ラムダ式)
Function
23
java.util.function.Consumerの説明として、正しいものを選びなさい。(1つ選択) (第八章 関数型インターフェース、ラムダ式)
引数を受け取り、その値を使って処理だけ行い、結果は戻さない
24
次のプログラムをコンパイル、実行した時の結果として、正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main { public static void main (String[] args) { int[] array = new int[0]; System.out.println(array); } } 〜〜〜 (第五章 配列の操作)
ハッシュコードが表示される
25
次のプログラムの説明として、正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main { public static void main(String[] args){ int[] a; int b[]; int[][] c; int d[][]; int[] e []; int[][] f[]; } } 〜〜〜 (第五章 配列の操作)
コンパイルエラーは発生しない
26
配列型変数の宣言として正しいものを選びなさい。(1つ選択) (第五章 配列の操作)
A〜Dまで全て誤り
27
次の中から、コンパイルエラーになるコードを選びなさい。(3つ選択) (第五章 配列の操作)
int a[] = new int[2][3];, int[] b = new int[2.3];, int f[][] = new int[][3];
28
次のプログラムをコンパイル、実行した時の結果として、正しいものを選びなさい。(1つ選択) //1~~~ public class Item { String name; int price = 100; } //2~~~ public class Main { public static void main(String[] args) { Item[] items = new Item[3]; int total = 0; for (int i = 0; i < items.length; i++){ total +=items[i].price; } System.out.println(total); } } 〜〜〜 (第五章 配列の操作)
実行時に例外がスローされる
29
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main { public static void main(String[] args){ String[] array = {“A” , ”B” , “C” , “D”}; array[0] = null; for (String str : array) { System.out.print(str); } } } 〜〜〜 (第五章 配列の操作)
「nullBCD」と表示される
30
次の中から、コンパイルエラーにならないコードを選びなさい。(3つ選択) (第五章 配列の操作)
int b[][] = {};, int[][] c = new int[][]{};, int[] d; d = new int[]{ 2 , 3 };
31
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { String[][] array = {{"A","B"},null,{"C","D","E"}}; int total = 0; for(String[] tmp : array){ total += tmp.length; } System.out.println(total); } } ~~~ (第五章 配列の操作)
実行時に例外がスローされる
32
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) //1~~ public interface A {} //2~~ public abstract class B implements A {} //3~~ public class C extends B {} //4~~ public class D extends C {} //5~~ public class Main { public static void main(String[] args) { A[] array = {new C(), null, new D()}; Object[] objArray = array; } }
コンパイルも実行も可能
33
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { int[][] arrayA = {{1,2}, {1,2}, {1,2,3}}; int[][] arrayB =arrayA.clone(); int total = 0; for(int[] tmp : arrayB){ for(int val : tmp){ total += val; } } System.out.println(total); } } ~~~ (第五章 配列の代入)
12が表示される
34
コンソール0〜4までの数字を順に表示したい。プログラムの5行目の空欄に入るコードとして、正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main{ public static void main(String[] args){ int a = 11; int b = 0; while ( 「 ? 」 ) { if (5 < a) { System.out.println(b); } a--; b++; } } } 〜〜〜 (第四章 制御構造)
b < 5
35
コンソール0〜4までの数字を順に表示したい。プログラムの空欄①と②に入るコードの組み合わせとして正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main{ public static void main(String[] args){ int a = 0; 『 ① 』{ System.out.println(a++); } 『 ② 』 } } 〜〜〜 (第四章 制御構造)
①do ②while (a < 5);
36
次のプログラムをコンパイル、実行した時の結果として、正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main{ public static void main(String[] args){ int a = 0; while (a < 5) do a++; System.out.print(a); while(true); } } 〜〜〜 (第四章 制御構造)
コンパイルエラーが発生する
37
次のプログラムをコンパイル、実行した時の結果として、正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main{ public static void main(String[] args){ for (int i = 1, long j = 2; i < 5; i++){ System.out.print( i * j ); } } } 〜〜〜 (第四章 制御構造)
コンパイルエラーが発生する
38
次のプログラムをコンパイル、実行した時の結果として、正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main{ public static void main(String[] args){ int a = 1; for (int b = 2, total = 0; b <= 5; b++){ total = a * b; } System.out.println( total ); } } 〜〜〜 (第四章 制御構造)
コンパイルエラーが発生する
39
次のプログラムを実行し、コンソールに「0」と表示したい。 3行目の空欄「 ? 」に入るコードとして正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main{ public static void main(String[] args){ for (int i = 0, 「 ? 」; i++){ System.out.println( i ); } } } 〜〜〜 (第四章 制御構造)
i == 0
40
次のプログラムをコンパイル実行した時の結果として、正しいものを選びなさい。(1つ選択) 〜〜〜 public class Main{ public static void main(String[] args){ for (int i = 0, j = 0; i < 3, j < 5; i++){ System.out.println(i++); j += i; } } } 〜〜〜 (第四章 制御構造)
コンパイルエラーが発生する
41
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { for(int i = 0; i < 3; i++, period()){ System.out.print(i); } } private static void period(){ System.out.print(","); } } ~~~ (第四章 制御構造)
「0,1,2,」と表示される
42
次のプログラムを実行して、コンソールに「10」を表示したい。 6行目の空欄に入るコードとして、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { int array[][] = new int[][] {{ 1, 2 }{ 2, 3, 4 }}; int total = 0; for(int i = 0; i < array.length; i++){ for (「 ? 」){ total += array[i][j]; } } System.out.println(total); } } ~~~ (第四章 制御構造)
int j = i; j < array[ i ].length; j++
43
次のプログラムの3行目の空欄に記述すると無限ループになるコードを選びなさい。(3つ選択) ~~~ public class Main { public static void main(String[] args) { for(「 ? 」){ System.out.println(i); } } } ~~~ (第四章 制御構造)
int i = 0; true; i++, int i = 0; ; i++, int i = 0; i < 5;
44
次のプログラムの4行目の空欄に記述するコードとして、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { String[][] array = {{"A","B","C"}}; for(「 ? 」){ System.out.print(obj); } } } ~~~ (第四章 制御構造)
Object obj : array
45
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { String[] array = {"A","B","C"}; for(String str : array){ str = "D"; } for(String str : array){ System.out.println(str); } } } ~~~ (第四章 制御構造)
「ABC」と表示される
46
次のコードと同じ結果を出力するコードを選びなさい。(1つ選択) ~~~ int num = 10; do { num++; } while (++num < 10); System.out.println(num); ~~~ (第四章 制御構造)
A~Dすべて誤り
47
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { String[] array = {"A","B"}; for(String a : array){ for (String b : array){ if ("B".equals(b)) break; System.out.print(b); } } } } ~~~ (第四章 制御構造)
「AA」と表示される
48
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { int[] array = { 1, 2, 3, 4, 5 }; int total = 0; for(int i : array){ if(i % 2 == 0) continue; total += i; } System.out.println(total); } } ~~~ (第四章 制御構造)
9が表示される
49
次の中から、ラベルが記述できるものを選びなさい。(1つ選択) (第四章 制御構造)
AからEすべて
50
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { int total = 0; a: for(int i = 0; i < 5; i++){ b: for(int j = 0; j < 5; j++){ if(i % 2 == 0) continue a; if(3 < j) break b; total += j } } System.out.println(total); } } ~~~ (第四章 制御構造)
12が表示される
51
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { try{ int[] array = {}; array[0] = 10; System.out.println("finish"); }catch(ArrayIndexOutOfBoundsException e){ System.out.println("error"); } } } ~~~ (第十章 例外処理)
「error」と表示される
52
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。 なお、実行時には起動パラメータをなにも渡さないこととする。(1つ選択) ~~~ public class Main { public static void main(String[] args) { try{ if(args.length == 0){ System.out.println("A"); } }catch(ArrayIndexOutOfBoundsException e){ System.out.println("B"); }finally{ System.out.println("C"); } } } ~~~ (第十章 例外処理)
「A」「C」と表示される
53
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) //1~~~ public class SampleException extends Exception{} //2~~~ public class SubSampleException extends SampleException{} //3~~~ public class Main { public static void main(String[] args) { try{ sample(); sub(); }catch(SampleException e){ System.out.println("A"); }catch(SubSampleException e){ System.out.println("B"); } } private static void sample() throws SampleException{ throw new SampleException(); } private static void sub() throws SubSampleException{ throw new SubSampleException(); } } ~~~ (第十章 例外処理)
コンパイルエラーが発生する
54
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { try{ Object obj = null; System.out.println(obj.toString()); System.out.println("A"); }finally{ System.out.println("B"); }catch(NulPointerException e){ System.out.println("C"); } } } ~~~ (第十章 例外処理)
コンパイルエラーが発生する
55
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { System.out.println(test(null)); } private static String test(Object obj){ try{ System.out.println(obj.toString()); }catch(NullPointerException e){ return "A"; }finally{ System.out.println("B"); } return "C"; } } ~~~ (第十章 例外処理)
「B」「A」と表示される
56
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) //~~~ public class Main { public static void main(String[] args) { int result = sample(); System.out.println(result); } private static int sample(){ try{ throw new RuntimeException(); }catch(RuntimeException e){ return 10; }finally{ return 20; } } } //~~~ (第十章 例外処理)
20が表示される
57
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) //~~~ public class Main { public static void main(String[] args) { int result = sample(); System.out.println(result); } private static int sample(){ int val = 0; try{ String[] array = {"A","B","C"}; System.out.println(array[3]); }catch(RuntimeException e){ val = 10; return val; }finally{ val += 10; } return val; } } //~~~ (第十章 例外処理)
10が表示される
58
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) //~~~ public class Main { public static void main(String[] args) { try{ System.out.println("A"); }finally{ System.out.println("B"); }finally{ System.out.println("C"); } } } //~~~ (第十章 例外処理)
コンパイルエラーが発生する
59
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) //~~~ public class Main { public static void main(String[] args) { try{ try{ String[] array = {"a","b","c"}; System.out.println(array[3]); }catch(ArrayIndexOutOfBoundsException e){ System.out.println("d"); }finally{ System.out.println("e"); } }catch(ArrayIndexOutOfBoundsException e){ System.out.println("f"); }finally{ System.out.println("g"); } } } //~~~ (第十章 例外処理)
「d」「e」「g」と表示される
60
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) //~~~ import java.io.FileInputStream; import java.io.FileNotFoundException; public class Sample { public static void main(String[] args) { try(FileInputStream is = new FileInputStream("sample.txt")){ throw new FileNotFoundException(); }catch(Exception e){ System.out.println("A"); }finally{ if (is != null){ is.close(); } System.out.println("B"); } } } //~~~ (第十章 例外処理)
コンパイルエラーが発生する
61
次のSampleクラスの2行目の空欄に入るコードとして、正しいものを選びなさい。(2つ選択) //1~~~ public class SampleException extends Exception {} //2~~~ public class TextException extends RuntimeException {} //3~~~ public class Sample { public void hello(String name) 「 ? 」{ if(name == null){ throw new SampleException(); } if("".equals(name)){ throw new TextException(); } // do something } } //~~~ (第十章 例外処理)
throws SampleException, TextException, throws SampleException
62
エラーに関する説明として、誤っているものを選びなさい。(1つ選択) (第十章 例外処理)
エラーは例外処理を記述できない
63
次のプログラムを確認してください。 public class Main { public static void main(String[] args) { System.out.println(args[0].length()); } } このプログラムを次のコマンドで実行したときの結果として、正しいのもを選びなさい (1つ選択) >java Main (第十章 例外処理)
ArrayIndexOutOfBoundsExceptionが発生する
64
次のプログラムをコンパイル、実行したときに発生する例外の種類として、 正しいものを選びなさい。(1つ選択) import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.get(0); } } (第十章 例外処理)
IndexOutOfBoundsException
65
次のプログラムを確認してください。 ~~~ public class A { private int num; public A(int num){ this.num = num; } public boolean equals(Object obj){ A a = (A) obj; return this.num == a.num; } } ~~~ public class B { private int num; public B(int num){ this.num = num; } public boolean equals(Object obj){ B b = (B) obj; return this.num == b.num; } } ~~~ これらのクラスを利用する以下のプログラムを コンパイル、実行したときの結果として、正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { A a = new A(10); B b = new B(10); System.out.println(a.equals(b)); } } (第十章 例外処理)
実行時に例外がスローされる
66
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { String str = null; if (str.equals("")){ System.out.println("blank"); }else{ System.out.println("null"); } } } (第十章 例外処理)
NullPointerExceptionが発生する
67
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { main(args); } } (第十章 例外処理)
StackOverflowErrorが発生する
68
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { int a = 3; int b = a += 5; System.out.println(a + b); } } (第三章 演算子と判定構造)
16が表示される
69
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { int num = -10; System.out.println(10 * -num); } } (第三章 演算子と判定構造)
100が表示される
70
次の式のうち、コンパイルエラーになるものを選びなさい。(3つ選択) (第三章 演算子と判定構造)
byte a = 0b10000000;, int c = 2 * 3L;, float d = 10.0;
71
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { int a = 10; int b = a++ + a + a-- - a-- + ++a; System.out.println(b); } } (第三章 演算子と判定構造)
32が表示される
72
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { boolean a = true; boolean b = true; System.out.println(a <= b); } } (第三章 演算子と判定構造)
コンパイルエラーが発生する
73
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { int a = 10; int b = 10; if(10 < a && 10 < ++b){ a++; } System.out.println(a + b); } } (第三章 演算子と判定構造)
20が表示される
74
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { int a = 100, b = 20, c = 30; System.out.println(a % b * c + a / b); } } (第三章 演算子と判定構造)
5が表示される
75
次のプログラムを確認してください。 ~~~ public class Sample { private int num; public Sample(int num){ this.num = num; } } このクラスを利用する以下ののプログラムを コンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) ~~~ public class Main { public static void main(String[] args) { Sample s1 = new Sample(10); Sample s2 = s1; s1 = new Sample(10); System.out.println(s1 == s2); } } (第三章 演算子と判定構造)
falseが表示される
76
次のプログラムを確認してください。 ~~~ public class Sample { private int num; private String name; public Sample(int num, String name){ this.num = num; this.name = name; } public boolean equals(Object obj){ if (obj == null){ return false; } if (obj instanceof Sample){ Sample s = (Sample) obj; return s.num == this.num; } return false; } } このクラスを利用する以下のプログラムを コンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) ~~~ public class Main { public static void main(String[] args) { Sample a = new Sample(10, "a"); Sample b = new Sample(10, "b"); System.out.println(a.equals(b)); } } (第三章 演算子と判定構造)
trueが表示される
77
次のプログラムを確認してください。 ~~~ public class Sample { private int num; private String name; public Sample(int num){ this.num = num; } public boolean equals(Sample obj){ if (obj == null){ return false; } return this.num == obj.num; } } このクラスを利用する以下のプログラムを コンパイル、実行したときの結果として正しいものを選びなさい。(1つ選択) ~~~ public class Main { public static void main(String[] args) { Object a = new Sample(10); Object b = new Sample(10); System.out.println(a.equals(b)); } } (第三章 演算子と判定構造)
「false」と表示される
78
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { Object a = new Object(); Object b = null; System.out.println(a.equals(b)); } } (第三章 演算子と判定構造)
「false」が表示される
79
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { String a = "sample"; String b = "sample"; System.out.print(a == b); System.out.print(", "); System.out.println(a.equals(b)); } } (第三章 演算子と判定構造)
「true, true」と表示される
80
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { String a = new String("sample"); String b = "sample"; System.out.print(a == b); System.out.print(", "); System.out.println(a.equals(b)); } } (第三章 演算子と判定構造)
「false, true」と表示される
81
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { String a = "abc"; String b = new String(a); int count = 0; if(a.intern() == "abc"){ count++; } if(b.intern() == "abc"){ count++; } if(a.intern() == b.intern()){ count++; } System.out.println(count); } } (第三章 演算子と判定構造)
3が表示される
82
次のプログラムを実行し、「ok」と表示したい。 4行目の空欄「 ? 」に入るコードとして、正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { int num = 10; 「 ? 」 System.out.println("ok"); } } (第三章 演算子と判定構造)
if (num <= 10)
83
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { if (false) System.out.println("A"); System.out.println("B"); } } (第三章 演算子と判定構造)
「B」と表示される
84
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { int num = 10; if (num < 10) System.out.println("A"); else System.out.println("B"); if(num == 10) System.out.println("C"); } } (第三章 演算子と判定構造)
「B」「C」と表示される
85
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { int num = 10; if (num == 100) System.out.println("A"); else if (10 < num) System.out.println("B"); else if(num == 10) System.out.println("C"); else if(num == 10) System.out.println("D"); } } (第三章 演算子と判定構造)
Cが表示される
86
switch文の条件式が戻せる形として、正しいものを選びなさい。(6つ選択) (第三章 演算子と判定構造)
char, byte, short, int, String, enum
87
次のプログラムをコンパイルエラーが発生するのは何行目か。 正しいものを選びなさい。(2つ選択) public class Main { public static void main(String[] args) { final int NUM = 0; int num = 10; switch (num){ case "10" : System.out.println("A"); break; case num : System.out.println("B"); break; case 2 * 5 : System.out.println("C"); break; case NUM : System.out.println("D"); break; } } } (第三章 演算子と判定構造)
6行目, 8行目
88
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) public class Main { public static void main(String[] args) { int num = 1; switch (num){ case 1: case 2: case 3: System.out.println("A"); case 4: System.out.println("B"); default: System.out.println("C"); } } } (第三章 演算子と判定構造)
「A」「B」「C」と表示される
89
次の計算式を使い、毎年積立を行って複利運用したときの金額を計算したい。 この計算を行うコードとして正しいものを選びなさい。(1つ選択)
n = (int)(m * (Math.pow(( 1 + r ), x) - 1 ) / r );
90
次のプログラムをコンパイル、実行したときの結果として正しいものを選びなさい。 (1つ選択) ~~~ public class Sample { private int id; private String name; public Sample(int id, String name){ super(); this.id = id; this.name = name; } public int getId(){ return id; } public String getName(){ return name; } } ~~~ import java.util.Comparator; public class SampleComparator implements Comparator<Sample> { @Override public int compare(Sample s1, Sample s2){ if(s1.getId() < s2.getId()){ return 1; } if(s2.getId() < s1.getId()){ return -1; } return 0; } } ~~~ import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static void main(String[] args) { Sample[] samples = { new Sample(2,"B"), new Sample(3,"C"), new Sample(1,"A") }; List<Sample> list = new ArrayList<Sample>(Arrays.asList(samples)); list.sort(new SampleComparator()); for (Sample s : list){ System.out.println(s.getName()); } } } (第九章 API)
「C」「B」「A」と表示される
91
次のプログラムを実行し、「3」「2」「1」を表示したい。 空欄「 ? 」に入るコードとして正しいものを選びなさい。(1つ選択) import java.util.Arrays; import java.util.List; public class Main { public static void main(String[] args) { List<Integer> list = Arrays.asList(new Integer[] {1, 2, 3}); 「 ? 」 for (Integer num : list){ System.out.println(num); } } } (第九章 API)
list.sort((a,b) -> -a.compareTo(b));
92
次のプログラムをコンパイル、実行した時の結果として、正しいものを一つ選びなさい。(1つ選択) public class Main { public static void main(String[] args) { char a = '0'; int num = 0; if (Character.isAlphabetic(a)){ num++; } if (Character.isDigit(a)){ num++; } if (Character.isLowerCase(a)){ num++; } System.out.println(num); } } (第九章 API)
1が表示される
93
次のプログラムをコンパイル、実行した時の結果として、正しいものを一つ選びなさい。(1つ選択) import java.time.LocalDate; public class Main { public static void main(String[] args) { LocalDate a = LocalDate.of(2015, 0, 1); LocalDate b = LocalDate.parse("2015-01-01"); System.out.println(a.equals(b)); } } (第九章 API)
実行時に例外がスローされる
94
次のプログラムをコンパイル、実行した時の結果として、正しいものを一つ選びなさい。 ただし、現在の日付は2019年8月20日とする。(1つ選択) import java.time.LocalDate; import java.time.DayOfWeek; public class Main { public static void main(String[] args) { LocalDate a = LocalDate.of(2019, 8, 19); LocalDate b = LocalDate.now(); b.with(DayOfWeek.MONDAY); System.out.println(a.equals(b) + ", " + a.isBefore(b)); } } (第九章 API)
「false, true」と表示される
95
次のうち、ArrayListの説明として正しいものを選びなさい。(3つ選択) (第九章 API)
動的な配列として動作する, スレッドセーフではない, 値を追加する箇所を制御できる
96
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList list = new ArrayList<>(); list.add("A"); list.add(10); list.add('B'); for (Object obj : list){ System.out.print(obj); } } } (第九章 API)
「A10B」と表示される
97
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("A"); list.add(2, "B"); list.add("C"); list.add("D"); for (String str : list){ System.out.print(str); } } } (第九章 API)
実行時に例外がスローされる
98
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) import java.util.ArrayList; public class Main { public static void main(String[] args){ ArrayList<String> list = new ArrayList<>(); list.add("A"); list.set(0,"B"); list.add("C"); list.set(1,"D"); for (String str : list){ System.out.print(str); } } } (第九章 API)
「BD」が表示される
99
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) ~~ public class Item { private String name; private int price; public Item(String name, int price){ this.name = name; this.price = price; } public boolean equals(Object obj){ if(obj instanceof Item){ Item tmp = (Item) obj; if(tmp.name.equals(this.name)){ return true; } } return false; } public String getName(){ return name; } } ~~~ import java.util.ArrayList; public class Main { public static void main(String[] args){ ArrayList<Item> list = new ArrayList<>(); list.add(new Item("A", 100)); list.add(new Item("B", 200)); list.add(new Item("C", 300)); list.add(new Item("A", 100)); list.remove(new Item("A", 500)); for (Item item : list){ System.out.println(item.getName()); } } } (第九章 API)
「B」「C」「A」と表示される
100
次のプログラムをコンパイル、実行したときの結果として、正しいものを選びなさい。(1つ選択) import java.util.ArrayList; public class Main { public static void main(String[] args){ ArrayList<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add("C"); for (String str : list){ if("B".equals(str)){ list.remove(str); }else{ System.out.println(str); } } } } (第九章 API)
「A」が表示される