简体   繁体   English

Java不会运行该类

[英]Won't run the class, Java

I was following a book on to learn java when it told me to enter this code: 当我告诉我输入以下代码时,我正在关注一本关于学习Java的书:

package com.thekyle.hi;

class Myclass {
    int x;

    Myclass(int i) {
        x = i;
    }
}

class ParmsConsDemo {
    public static void main(String args[]) {
        Myclass t1 = new Myclass(10);
        Myclass t2 = new Myclass(88);
        System.out.println(t1.x + " " + t2.x);

    }
}// OutPut is 10 88

And it will launch a different class than this one. 它将推出与本课程不同的课程。 How do I make it launch? 如何启动它?

Do this as follows 如下进行

  1. First, you need make sure the java file name has the same as your class name. 首先,您需要确保Java文件名与您的类名相同。 see the red circle in the screen shot below. 请参见下面的屏幕快照中的红色圆圈。

在此处输入图片说明

  1. Right click on your source code. 右键单击您的源代码。 Run As> Run Configurations... then in Run configuration pop up window, you need make sure that it is filled up with the right project name and Main class name, which is ParmsConsDemo in your case. 运行方式>运行配置...,然后在运行配置弹出窗口中,请确保它填充有正确的项目名称和主类名称,在您的情况下为ParmsConsDemo。 see the screen shot below: 请参阅以下屏幕截图:

在此处输入图片说明

Make ParmsConsDemo public. ParmsConsDemo公开。

...
public class ParmsConsDemo {
 ...
  public static void main(String[] args){
    ..
  }
...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM