W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
// 创建 Main 类
public class Main {
 
  // 创建 fullThrottle() 方法
  public void fullThrottle() {
    System.out.println("汽车正在全速前进!");
  }
​
  // 创建 speed() 方法并添加参数
  public void speed(int maxSpeed) {
    System.out.println("最高时速是:" + maxSpeed);
  }
​
  // 在 main 方法中调用 myCar 对象的方法
  public static void main(String[] args) {
    Main myCar = new Main();     // 创建 myCar 对象
    myCar.fullThrottle();      // 调用 fullThrottle() 方法
    myCar.speed(200);          // 调用 speed() 方法
  }
}