【问题标题】:Java: System.out.print Error in main() | out needs to be an object in abstract class (not)Java:main() 中的 System.out.print 错误 | out 需要是抽象类中的对象(不是)
【发布时间】:2015-07-09 13:24:16
【问题描述】:

https://github.com/AquaSolid/Interactions

找不到符号 符号:变量输出 location: class System //

 public class Interactions {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    System.out.println("Welcome to Interactions."); }}

【问题讨论】:

  • 能否请您澄清一下
  • 我建议看图。老实说,我不知道发生了什么,也许是继承问题? System.out.println 中的“out”显示错误。
  • 不要创建一个名为“System”的类..
  • 啊哈,谢谢,很抱歉打扰大家,大概就是这样。不太可能,肯定的。

标签: java system


【解决方案1】:

您已通过在包中添加 System 类来隐藏 java.lang.System。这可以通过完整路径引用 java.lang.System 来解决:

 public class Interactions {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    java.lang.System.out.println("Welcome to Interactions."); }}

【讨论】:

  • 虽然使用完全限定名称可以解决问题,但值得注意的是,它可能会相当混乱。重命名“系统”类可能是一个更好的主意,但这肯定仍然可以解决问题! +1
  • 完全修复,愚蠢的菜鸟错误,谢谢大家。将其重命名为组织。
【解决方案2】:

不要创建一个名为“System”的类,我看到你有一个“System.java”。

给它起个别的名字。

System 是一个内置的 Java 类!

【讨论】:

  • 创建一个类'System'真的没有问题。有一个简单的解决方法。看我的回答。
  • @ControlAltDel 是的,我知道这样做不是问题。我对你的回答发表了评论,毫无疑问这很好,但我认为不应该鼓励它。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多