Java 17 Silver ラボ

学習の画面へ

static な private メソッド

出力はどれか。

public class Main {
    public static void main(String[] args) {
        System.out.println(Calc.twice(3) + Calc.square(3));
    }
}

interface Calc {
    static int twice(int n) { return times(n, 2); }

    static int square(int n) { return times(n, n); }

    private static int times(int a, int b) { return a * b; }
}
  1. A 15
  2. B 69
  3. C コンパイルエラーになる
  4. D 実行時に例外が発生する
正解と解説を見る

正解: A

ポイント

「デフォルト・メソッドとプライベート・メソッドの使用」をこのサイトで解く (記録・間違えた問題の解き直し・AI教師への質問)