Java Silverに関する問題を出題していきます!
問題1
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface MyInterface { String message = "hello"; } public class Sample implements MyInterface { public static void main(String[] args) { MyInterface obj = new MyInterface(); System.out.println(obj.message); } }
- 「hello」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
- 1~4以外
問題2
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface MyInterface { String message = "hello"; } class Imp implements MyInterface { public String getMessage() { return message; } } public class Sample { public static void main(String[] args) { Imp obj = new Imp(); String message = obj.getMessage(); System.out.println(message); } }
- 「hello」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
- 1~4以外
問題3
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface MyInterface { String message = "hello"; String getMessage(); } class Imp implements MyInterface { @Override String getMessage() { return message; } } public class Sample { public static void main(String[] args) { Imp obj = new Imp(); String message = obj.getMessage(); System.out.println(message); } }
- 「hello」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
- 1~4以外
問題4
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface MyInterfaceA { String message = "hello"; } interface MyInterfaceB { String getMessage(); } class Imp implements MyInterfaceA, MyInterfaceB { @Override public String getMessage() { return message; } } public class Sample { public static void main(String[] args) { Imp obj = new Imp(); String message = obj.getMessage(); System.out.println(message); } }
- 「hello」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
- 1~4以外
問題5
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
interface MyInterface { String message = ""; } class Imp implements MyInterface { String getMessage() { message = "hello"; return message; } } public class Sample { public static void main(String[] args) { Imp obj = new Imp(); String message = obj.getMessage(); System.out.println(message); } }
- 「hello」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
- 1~4以外