先上源码

public class Tom{
  int leg;
  String head;
  void cry(String s){
    System.out.println(s);
  }
}
class Example{
  public static void main(String args[]){
  Tom cat;
  cat=new Tom();
  cat.leg=4;
  cat.head="猫头";
  System.out.println("腿:"+cat.leg+"条");
  System.out.println("头:"+cat.head);
  cat.cry("我今天要和杰瑞拼了");
  }
}

Java学习笔记:找不到主类
这里错误原因并不是程序有问题,而是命令不对。解释器(java.exe)对象必须是主类!而编译器(javac.exe)对象为源文件名,即public 类。
Tom.Java中主类为Example,自然在Tom中找不到main方法,而应该用java Example命令。

相关文章:

  • 2021-11-18
  • 2021-11-18
  • 2022-01-01
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
猜你喜欢
  • 2021-08-27
  • 2021-10-30
  • 2022-12-23
  • 2021-04-12
  • 2021-04-26
  • 2021-11-30
  • 2021-06-16
相关资源
相似解决方案