Java Silverに関する問題を出題していきます!
問題1
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface Greeting { String message = "hello"; } class Imp implements Greeting {} public class Practice25_Q1 { public static void main(String[] args) { Imp obj1 = new Imp(); Imp obj2 = new Imp(); System.out.println(obj1.message == obj2.message); } }
- 「true」と表示
- 「false」と表示
- コンパイルエラー
- 実行時エラー
- 1~4以外
問題2
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface Greeting { char[] message = {'h', 'e', 'l', 'l', 'o'}; } class Imp implements Greeting {} public class Practice25_Q2 { public static void main(String[] args) { Imp obj1 = new Imp(); obj1.message[0] = 'こ'; obj1.message[1] = 'ん'; obj1.message[2] = 'に'; obj1.message[3] = 'ち'; obj1.message[4] = 'は'; Imp obj2 = new Imp(); System.out.println(obj1.message == obj2.message); } }
- 「true」と表示
- 「false」と表示
- コンパイルエラー
- 実行時エラー
- 1~4以外
問題3
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface Greeting { String message = "hello"; void greet() { System.out.println("hello"); } } class Imp implements Greeting {} public class Practice25_Q3 { public static void main(String[] args) { Imp obj = new Imp(); obj.greet(); } }
- 「hello」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
- 1~4以外
問題4
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface English { String message = "hello"; } interface Japanese { String message = "こんにちは"; } class Imp implements English, Japanese { void greet() { System.out.println(message); } } public class Practice25_Q4 { public static void main(String[] args) { Imp obj = new Imp(); obj.greet(); } }
- 「hello」と表示
- 「こんにちは」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
問題5
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface English { String message = "hello"; } interface Japanese { String message = "こんにちは"; } class Imp implements English, Japanese { void greet() { System.out.println(English.message); } } public class Practice25_Q5 { public static void main(String[] args) { Imp obj = new Imp(); obj.greet(); } }
- 「hello」と表示
- 「こんにちは」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー