Output-Based Java Questions

This Java quiz is a set of classic "what is the output?" questions from interviews and written tests. Each one hides a rule about operators, overloading, initialization order or number types that you need to know cold.

Trung bình 10 câu hỏi ~6 phút Đạt từ 80% Java 17

Chọn chế độ

Bạn đang chơi với tư cách khách: đăng nhập để lưu XP và streak.

Câu hỏi mẫu

Câu 1/10

What does this print?

public class Main {
    public static void main(String[] args) {
        System.out.println('a' + 1 + "b" + 'a' + 1);
    }
}
Xem đáp án

B. 98ba1 + is evaluated left to right. 'a' + 1 is char + int, so it is numeric addition: 97 + 1 = 98. Once a String appears, everything after it is concatenated as text.

Quiz này có gì

  • char arithmetic and string concatenation order
  • Pre- and post-increment in one expression
  • Overload resolution with null
  • Static blocks, instance blocks and constructors
  • Rounding, overflow, Infinity and NaN

Câu hỏi thường gặp

Có cần tài khoản không?

Không. Ai cũng chơi được. Đăng nhập để lưu XP, streak, badge và lịch sử.

Có làm lại được không?

Được. Điểm cao nhất của bạn được giữ lại, câu hỏi và đáp án được xáo trộn mỗi lần.