Java 模擬問題集
ランダム
未解答
評価
次のプログラムをコンパイルするとどうなるか。
01: import java.io.*;
02: package hogepack;
03:
04: public class Sample {
05: public Sample() {
06: System.out.println("Hello!");
07: }
08:
09: public static void main(String[] args) {
10: Sample s = new Sample();
11: }
12: }
正解率:61%
| 評価:1
| |
|
1~10の中で偶数のみを合計する関数を作成する。
正しいものを全て選べ。
public class hoge {
public static void main(String[] args)
{
int sum = 0;
int i = 1;
//1~10の整数のうち、偶数を足す
【ア、イ】
{
// 偶数か
【ウ、エ】
}
System.out.println(sum);
}
}
ウ
if (i % 2 ==0 )
{
sum += i;
}
エ
switch(i % 2)
{
case 0:
sum += i;
break;
default:
break;
}
正解率:35%
| 評価:0
| |
|
Javaの例外処理について書かれた次の文章について正しいものを全て選択してください。
正解率:56%
| 評価:12
| |
|
次のプログラムをコンパイルし、実行するとどうなるか、正しいものを選択してください。
class Sample {
public static void main(String[] args) {
System.out.println(args[1]);
}
}
コンパイル後、次のコマンドを実行するものとします。
java Sample 0 1
正解率:79%
| 評価:10
| |
|
以下のプログラムをコンパイル、実行した場合の結果として、正しいものを以下から選びなさい。
public class Test {
public static void main(String[] args) {
for (int i=3; i<3; i++){
System.out.println(i);
}
}
}
正解率:83%
| 評価:0
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
1.
2. public class Person {
3. String name = "no name";
4. public Person(String nm){ name = nm;}
5. }
6.
7. public class Employee extends Person{
8. String empId = "0000";
9. public Employee(String id){
10. empId = id;
11. }
12. }
13.
14. public class EmployeeTest {
15. public static void main(String[] args) {
16. Employee e = new Employee("4321");
17. System.out.println(e.empId);
18. }
19. }
20.
正解率:41%
| 評価:28
| |
|
次の式のソースコードを実行した時に、【 A 】に入れると「10」と出力されるものをすべて選べ
public class hoge {
public static void main(String[] args)
{
int hoge = 0;
// 10になる式
【 A 】
System.out.println(hoge);
}
}
正解率:35%
| 評価:0
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
class Exam {
private Exam() {}
static void textPrint() {
System.out.println("Exam");
}
}
public class Sample extends Exam {
public static void main(String[] args) {
Sample.textPrint();
}
static void textPrint() {
System.out.println("Sample");
}
}
正解率:43%
| 評価:0
| |
|
次のプログラムをコンパイルして、10と出力されるものはどれか。
===========================================
【ア】
public class hoge
{
public static void main(String[] args)
{
testClass test = new testClass();
test.print();
}
}
// クラス
class testClass
{
// 出力
public void print()
{
System.out.println(10);
}
}
===========================================
【イ】
public class hoge
{
public static void main(String[] args)
{
testClass test = new testClass();
test.print();
}
}
//クラス
class testClass
{
// 変数
int iNum;
// コンストラクタ
testClass()
{
iNum = 10;
}
// 出力
public void print()
{
System.out.println(iNum);
}
}
===========================================
【ウ】
public class hoge
{
public static void main(String[] args)
{
testClass test = new testClass();
test.print();
}
}
// クラス
class testClass
{
// 変数
int iNum;
// コンストラクタ
testClass()
{
iNum = 10;
}
testClass(int argInt)
{
iNum = argInt;
}
// 出力
public void print()
{
System.out.println(iNum);
}
}
===========================================
【エ】
public class hoge
{
public static void main(String[] args)
{
testClass test = new testClass(9);
test.print();
}
}
// クラス
class testClass
{
// 変数
int iNum;
// コンストラクタ
testClass()
{
iNum = 10;
}
testClass(int argInt)
{
iNum = argInt;
}
// 出力
public void print()
{
System.out.println(iNum);
}
}
===========================================
【オ】
public class hoge
{
public static void main(String[] args)
{
testClass test = new testClass();
test.setNum(10);
test.print();
}
}
//クラス
class testClass
{
// 変数
int iNum;
// コンストラクタ
testClass()
{
}
testClass(int argInt)
{
setNum(argInt);
}
// 数値格納
void setNum(int argInt)
{
iNum = argInt;
}
// 出力
public void print()
{
System.out.println(10);
}
}
正解率:50%
| 評価:0
| |
|
下記の選択肢の中から正しいものを選べ
正解率:56%
| 評価:0
| |
|
以下のプログラムをコンパイル、実行した場合の結果として、正しいものを以下から選びなさい。
public class Test {
public static void main(String[] args) {
int i = 3;
do {
System.out.println(i);
i++;
} while (i<3);
}
}
正解率:82%
| 評価:12
| |
|
次のコードの内、コンパイルエラーにならないものをすべて選択してください。ここで、SubはSuperのサブクラスであるとします。
正解率:17%
| 評価:2
| |
|
次のプログラムを実行すると、Hello Java World.を3回出力するようにしたい。空欄に入る適切な組み合わせはどれか。
public class Sample {
public 【 A 】 void 【 B 】(String[] args) {
for(int i = 0; i < 【 C 】; i++) {
System.out.println("Hello Java World.");
}
}
}
正解率:83%
| 評価:0
| |
|
下記のソースコードは構文エラーがある。
何行目が間違っているか。(01~16の数字を解答欄アに解答する)
01://「hoge」と表示するプログラム
02:public class hoge {
03:
04: /* main関数
05: *
06: * 必須のメソッド
07: *
08: * args コマンドライン引数
09: * */
10: public static void main(String[] args)
11: {
12: /* hogeと出力
13: System.out.println("hoge");
14: }
15:
16:}
正解率:51%
| 評価:0
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
class MyException extends Exception {
public MyException() {
super("MyException");
}
}
class Sample {
public static void main(String[] args) {
try {
message(1);
} catch(MyException e) {
System.out.println(e.getMessage());
} finally {
System.out.println("finally");
}
}
static void message(int num) throws MyException {
if(num > 0) {
throw new MyException();
}
}
}
正解率:64%
| 評価:0
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
class Sample {
public static void main(String[] args) {
int num = 10;
num = meth(num);
if(num == 10) {
System.out.println("OK");
} else {
System.out.println("NG");
}
}
static int meth(int num) {
return ++num;
}
}
正解率:78%
| 評価:21
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
import java.util.*;
class Sample {
public static void main(String[] args) {
ArrayList al = new ArrayList<String>();
al.add(10);
al.add("20");
al.add(30);
Iterator it = al.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
}
}
正解率:40%
| 評価:14
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
class Sample {
public static void main(String[] args) {
int num = 10;
Data data = new Data();
data.setNum(num);
num = data.getNum();
System.out.println(num);
}
}
class Data {
int num = 50;
void setNum(int num) {
this.num = num + 10;
}
int getNum() {
return num;
}
}
正解率:61%
| 評価:68
| |
|
以下の文を実行した結果として正しいものを、選択肢から選びなさい。
int i =2;
int j = i++ + (i++ + ++i) + ++i;
正解率:46%
| 評価:44
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
01: class Sample {
02: public static void main(String[] args) {
03: int a = 10;
04: byte b = (byte)a;
05: String c = (String)b;
06: System.out.println("OK");
07: }
08: }
正解率:62%
| 評価:94
| |
|
以下の式をコンパイル、実行したときの結果として、正しいものを選びなさい(ただし式が正常に実行できるように、クラスは正しく作成されているものとする)。
System.out.println("1+2="+1+2);
正解率:63%
| 評価:33
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
1. public class Test {
2. public static void parse(String str){
3. try{
4. float f = Float.parseFloat(str);
5. } catch(NumberFormatException nfe){
6. f = 0;
7. } finally{
8. System.out.println(f);
9. }
10. }
11.
12. public static void main(String[] args) {
13. parse("invalid");
14. }
15. }
16.
正解率:40%
| 評価:32
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
class MyException extends Exception {
public MyException() {
super("MyException");
}
}
class Sample {
public static void main(String[] args) {
System.out.println("A");
method();
System.out.println("F");
}
static void method() {
try {
System.out.println("B");
throw new MyException();
} catch(MyException e) {
System.out.println("C");
} catch(Exception e) {
System.out.println("D");
} finally {
System.out.println("E");
}
}
}
正解率:54%
| 評価:20
| |
|
クラス「ArrayList」はどのパッケージに定義されているか。
正解率:78%
| 評価:10
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
01: class Sample {
02: public static void main(String[] args) {
03: int a = 10;
04: double b = a / 3;
05: System.out.println(b);
06: }
07: }
正解率:54%
| 評価:63
| |
|
次のプログラムの空欄Aに入れてもエラーとならない(コンパイルに成功する)ものを選んでください。
ただし、以下のクラスは同じパッケージ内にあるとします。
class Super {
【 A 】 int num;
}
class sub extends Super {
void setNum(int n) {
num = n;
}
}
正解率:41%
| 評価:15
| |
|
次はテキストファイル「data.txt」からデータを読み込むための読み込み用文字ストリームを作成する文です。
空欄アからウを埋めて文を完成させてください。
【 ア 】 br = 【 イ 】 【 ア 】 ( 【 イ 】 【 ウ 】 ("data.txt"));
正解率:40%
| 評価:0
| |
|
次の説明はOかXか?
Systemクラスのgc()メソッドを呼ぶことで、ガーベッジコレクションのタイミングを指定できる。
正解率:63%
| 評価:5
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
import java.util.*;
class Sample {
public static void main(String[] args) {
ArrayList<String> al = new ArrayList<String>();
al.add(10);
al.add(20);
al.add(30);
Iterator it = al.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
}
}
正解率:47%
| 評価:8
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
class Sample {
public static void main(String[] args) {
int[] a = {10, 20, 30};
int[] b = new int[3];
b = a;
a[0] = 100;
System.out.println(a[0] + ", " + b[0]);
}
}
正解率:63%
| 評価:2
| |
|
次のプログラムのメソッド中で生成する文字列「Java」を持つString型オブジェクトが、ガベージコレクションの対象となるのはいつか。正しいものを選択してください。
01: class Sample {
02: void textPrint() {
03: String a = new String("Java");
04: String b = new String("");
05: b = a;
06: System.out.println(a);
07: a = null;
08: b = null;
09: }
10: }
正解率:40%
| 評価:11
| |
|
java.util.zip.ZipFileクラスを利用するための正しいimport文をすべて選んでください。
正解率:50%
| 評価:5
| |
|
次の様なプログラムで、クラス「Sample」に定義されたメソッド「method」をオーバーライドするメソッドの定義はどれか。正しいものを選択してください。
オーバーライドするメソッドを空欄Aに記述するものとします。
class Sample {
protected void method(int a, String b) {}
}
class Sub extends Sample {
【 A 】
}
正解率:42%
| 評価:12
| |
|
次のプログラムをコンパイルし、実行した結果画面に表示される値は何か。解答欄アに入力してください。
コンパイルエラーとなる場合には「コンパイルエラー」、コンパイルは成功するが実行エラーとなる場合には「実行エラー」と入力してください。
class Sample {
public static void main(String[] args) {
Data data = new Data();
data.showNum();
}
}
class Data {
int num = 10;
void showNum() {
int num = 30;
this.num = this.num + num;
System.out.println(num);
}
}
正解率:50%
| 評価:10
| |
|
抽象メソッドの定義として正しいものはどれか。選択してください。
正解率:35%
| 評価:41
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
class Sample {
public static void main(String[] args) {
int a = 0;
do {
a++;
} while(a < 0);
switch(a) {
case 0:
System.out.println("A");
case 1:
System.out.println("B");
case 2:
System.out.println("C");
}
}
}
正解率:46%
| 評価:31
| |
|
次のコードは、コンパイルエラーになるか?
short s = 10;
char c = s;
正解率:68%
| 評価:20
| |
|
次の選択肢の内、コンパイルが通るものを選べ
public class hoge
{
public static void main(String[] args)
{
// longの最大値:9,223,372,036,854,775,807
【 空欄 】
System.out.println( var );
}
}
正解率:21%
| 評価:1
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。
正しい答えを選んでください。
class superClass {
void textPrint() {
System.out.println("superClass");
}
}
class subClass extends superClass {
void textPrint() {
System.out.println("subClass");
}
}
class Sample {
public static void main(String[] args) {
superClass sc = new subClass();
sc.textPrint();
}
}
正解率:76%
| 評価:0
| |
|
次のコードを実行した結果、変数「a」 ~ 変数「e」が参照するオブジェクトが格納する値を、解答欄「ア」 ~ 「オ」へ順番にtrueまたはfalseで解答してください。
ア) Boolean a = true;
イ) Boolean b = new Boolean("true");
ウ) Boolean c = new Boolean("TRUE");
エ) Boolean d = new Boolean("t r u e");
オ) Boolean e = new Boolean("ok");
正解率:32%
| 評価:14
| |
|
次のプログラムをコンパイルし、実行したとします。
class Sample {
public static void main(String[] args) {
try {
System.out.println("A");
int a = Integer.parseInt(args[1]);
System.out.println("B");
} catch(Exception e) {
System.out.println("C");
} finally {
System.out.println("D");
}
}
}
このとき、画面に
A
C
D
と表示されるのは、どのコマンドを実行した時か。正しいものを選択してください。
正解率:35%
| 評価:5
| |
|
次のプログラムをコンパイルし、実行した結果画面に表示される変数「a」の値は何か。解答欄アに入力してください。
class Sample {
public static void main(String[] args) {
int a = 0;
for(int i = 0; i < 3; i++) {
a += 2;
i = a;
}
System.out.println(a);
}
}
正解率:51%
| 評価:10
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
interface Exam {
int a = 1;
}
interface Lesson implements Exam {
int b = 2;
}
class Sample implements Lesson {
public static void main(String[] args) {
System.out.println(a + ", " + b);
}
}
正解率:52%
| 評価:11
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
class Sample {
public static void main(String[] args) {
char c = 'a';
c++;
System.out.println(c);
}
}
正解率:49%
| 評価:17
| |
|
次のプログラムの空欄Aに入れてもエラーとならない(コンパイルに成功する)ものはどれか。正しいものを選んでください。
class Sample {
public static void main(String[] args) {
【 A 】
}
}
正解率:53%
| 評価:0
| |
|
次のプログラムをコンパイルし、実行するとどうなるか。正しいものを選択してください。
01: class Exam {
02: int a = 10;
03: }
04: class Sample {
05: public static void main(String[] args) {
06: Exam exam = new Exam();
07: System.out.println(exam.a);
08: exam = null;
09: System.out.println(exam.a);
10: }
11: }
正解率:50%
| 評価:5
| |
|
変数名として使用できるのは?
正解率:73%
| 評価:1
| |
|
次のプログラムの実行結果として正しいものを
ア~オの選択肢から選びなさい。
public class Test {
public static void main(String args[]) {
HashSet<String> a = new HashSet<>();
LinkedHashSet<String> b = new LinkedHashSet<>();
TreeSet<String> c = new TreeSet<>();
Collections.addAll(a, "b", "b", "a", "a", "c", "c");
Collections.addAll(b, "b", "b", "a", "a", "c", "c");
Collections.addAll(c, "b", "b", "a", "a", "c", "c");
for(String text : a) System.out.print(text+" ");
for(String text : b) System.out.print(text+" ");
for(String text : c) System.out.print(text+" ");
}
}
正解率:69%
| 評価:21
| |
|
メソッド「method」の定義として正しい(コンパイルに成功する)ものはどれか。選んでください。
クラス「MyException」は、クラス「Exception」のサブクラスとして定義されているものとします。
正解率:38%
| 評価:5
| |
|
次のプログラムの空欄Aに入れてもエラーとならない(コンパイルに成功する)ものはどれか。正しいものを選んでください。
class Sample {
public static void main(String[] args) {
【 A 】 a = 100;
switch(a) {
case 100:
System.out.println("A");
break;
case 200:
System.out.println("B");
break;
case 300:
System.out.println("C");
break;
}
}
}
正解率:38%
| 評価:49
| |
|