Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建用IntelliJ Idea编译的Java子类?_Java - Fatal编程技术网

如何创建用IntelliJ Idea编译的Java子类?

如何创建用IntelliJ Idea编译的Java子类?,java,Java,下面是我关于继承的代码: class Noodle { double lengthInCentimeters; String shape; String texture = “brittle”; public void cook() { this.texture = "cooked"; } public static void main(String args) { Spaghetti spaghettiPomodor

下面是我关于继承的代码:

class Noodle {

    double lengthInCentimeters;
    String shape;
    String texture = “brittle”;

    public void cook() {
      this.texture = "cooked";
    }

    public static void main(String args) {
      Spaghetti spaghettiPomodoro = new Spaghetti();
      System.out.println(spaghettiPomodoro.texture);
    }

 }
我在谷歌上搜索了一个解决方案,唯一接近我需要的建议是: 如果您已经在项目视图中,请按Alt+Insert(New)| Class。项目视图可以通过Alt+1激活

要在与当前类相同的目录中创建新类,请使用Ctrl+Alt+Insert(new…)

您也可以从导航栏执行此操作,按Alt+Home,然后选择带有箭头键的软件包,然后按Alt+Insert

另一个有用的快捷方式是查看|在(Alt+F1)、项目(1)中选择,然后Alt+Insert在现有类附近创建一个类,或者使用箭头键在包中导航

还有一种方法是,只需在要使用它的现有代码中键入类名,IDEA将以红色突出显示它,因为它还不存在,然后按Alt+Enter键进入“意图操作”弹出窗口,选择“创建类”
我试过:ctrl+alt+insert。这将我带到一个GUI,在那里我被要求命名类,另外,从“类”、“接口”、“枚举”和“注释”中进行选择。我在“意大利面”中输入了名字,在“种类”中选择了“类”。这创建了一个看似子类“意大利面”,作为“面条”的子文件。我很高兴,因为我的代码中没有红色的曲线,但由于编译失败,我的快乐是短暂的。有人能告诉我我做错了什么吗?

无需使用快捷方式,您只需编写代码即可

我猜你的家长班叫
Spaghetti
。因此,您可以按如下方式编写代码:-

class Spaghetti{

        String texture = “brittle”;

        public void cook() {
          this.texture = "cooked";
        }
    }
面条
课程:

class Noodle extends Spaghetti{

        double lengthInCentimeters;
        String shape;
        String texture = “brittle”;

        public void cook() {
          this.texture = "cooked";
        }
    public static void main(String args) {
      Spaghetti spaghettiPomodoro = new Spaghetti(); //this is your parent class object
      System.out.println(spaghettiPomodoro.texture); //here you are calling instance 
                                                     //variable of parent class i.e. texture
      Noodle obj=new Noodle(); // this is child class object 
      System.out.println(obj.texture); //this will call child class instance variable "texture"

    }

 }

附言:-我建议你为主要方法制作一个单独的类

该类被切掉。这是“面条”共享的编译错误!
main
方法采用的是
String[]
而不是
String
我的问题是一个想法。“如何使用IntlliJ IDEA创建子类”。这个问题现在已经解决了。感谢所有发布回复的人。