模拟面试-2

发布: (2026年2月9日 GMT+8 10:47)
2 分钟阅读
原文: Dev.to

Source: Dev.to

面试问题

  1. 请介绍一下你自己?
  2. 为什么从机械工程转到 IT?
  3. 如果机械工程是你的第一选择,为什么现在选择 IT 课程?
  4. 为什么选择 Java?
  5. Java 容易学吗?
  6. 编译程序涉及哪些步骤?
  7. 执行时会发生什么?
  8. 如何在不使用 System.out.println() 的情况下产生输出?
  9. System.out.println() 会输出什么?
  10. 什么是控制流语句?
  11. 什么是 switch case?

示例 1

switch (x) {
    case 1:
        System.out.print("One ");
    case 2:
        System.out.print("Two ");
    case 3:
        System.out.print("Three ");
    default:
        System.out.print("Default");
}

输出: Two Three Default

示例 2

switch (x) {
    default:
        System.out.print("Default ");
    case 1:
        System.out.print("One ");
    case 2:
        System.out.print("Two ");
}

输出: Default One Two

示例 3

switch (ch) {
    case 'A':
        System.out.println("A");
        break;
    case 65:
        System.out.println("Sixty Five");
}

输出: A
'A' case 匹配;65 被视为 int。)

示例 4(switch 表达式)

String result = switch (day) {
    case 1 -> "Monday";
    case 2 -> "Tuesday";
    case 3 -> "Wednesday";
    default -> "Invalid";
};

System.out.println(result);

输出: Wednesday

0 浏览
Back to Blog

相关文章

阅读更多 »

Java 继承

什么是 Inheritance?Inheritance 是一种机制,其中一个 class 获取另一个 class 的 states 和 behaviors。它表示一种 is‑a relationship,意味着 …

什么是泛型?

Generics 是在 Java 5 中引入的一项功能,允许创建能够处理不同数据类型的类、接口和方法。它们消除……