问题标签 [main-method]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 主要方法和关键监听器
谁能告诉我为什么这个程序说我缺少一个主要方法?我在这段代码的底部有一个。
java - main方法可以放在父类中吗?如果是这样,可以在该主要方法中实例化子对象吗?
假设我有一个类'Person'和另一个类'Survey',它扩展了person,所以Survey是子类,Person类是父类。Person 是我编写的第一个类,因此现在在那里定义了 main 方法,因为我有一个子类,我可以从父类中的 main 方法调用子类的方法吗(或者我是否需要继续将 main 方法转移到尽管我确信这永远不会是必要的,但在等级制度中最低的阶级......)?如果是这样,这是否与子类继承父类的属性但父类不继承子类的任何属性的概念相悖?请务必回复。提前致谢。
此外,我还阅读了另一篇文章,其中有一个单独的类可能是 'driver.java 仅用于主方法,这是否意味着所有类都必须导入到这个类中才能让我们在主方法中调用其他类的方法?
我希望我的问题不会太复杂。
java - 错误:找不到主类
编译程序时出现错误
找不到主类:解决方案。程序将会退出。
该程序是:
java - Java 编程:main(String[] args) 中预期的编译器错误、类接口或枚举
我正在创建一个五子棋游戏。首先,我只是尝试输入一个 main 方法,以便我可以输入一些准备好变成真实的伪代码。但是,每当我尝试编译我当前的代码时,我都会在主字符串中的 'void' 之前得到一个编译器错误,指出:“class, interface or enum expected”。
我是 Java 编程新手,但在这方面已有数周的经验。我的一些朋友也在创建一个,他们也遇到了同样的问题。
我目前使用 BlueJ 作为我的开发环境。代码如下。
java - 使用 java 以编程方式从多个 main() 方法中查找默认 main() 方法
鉴于以下课程,我试图找到程序的主要入口点:
任何帮助表示赞赏,谢谢。
java - java中的合法主方法签名
当我尝试执行上面的代码时,它会显示一个错误,找不到主要方法。但是当我更改public static void main(String a)
为public static void main(String... a)
or时public static void main(String a[])
。然后,它工作..!!
所以,我的问题是我们可以用多少种不同的方式编写合法的主方法签名以及这个签名public static void main(String... a)
意味着什么?
java - 在控制台中打印ExamQuestion@143c8b3
我有一个类,它有一个采用字符串的方法。然后我有一个方法返回上述方法的值。当我在我的主类中获得返回值并打印它时,打印的值为“ExamQuestion@143c8b3”。如何让它正确打印?
谢谢
java - (Another) "non-static method cannot be referenced from a static context" issue
ERROR: non-static method cannot be referenced from a static context.
In my case the method is called readFile().
Hi. I'm experiencing the same error that countless novice programmers have before, but despite reading about it for hours on end, I can't work out how to apply that knowledge in my situation.
I think the code may need to be restructured so I am including the full text of the class.
I would prefer to house the main() method in small Main class, but have placed it in the same class here for simplicity. I get the same error no matter where I put it.
The readFile() method could easily be placed within the main() method, but I’d prefer to learn how to create small modular methods like this and call them from a main() method. Originally closeFile() was a separate method too.
The program is supposed to:
- open a .dat file
- read in from the file data regarding examination results
- perform calculations on the information
- output the results of the calculations
Each line of the file is information about an individual student.
A single consists of three examination papers.
Most calculations regard individual students.
But some calculations regard the entire collection of students (ie their class).
NB: where the word “class” is used in the code, it refers to academic class of the students, not class in the sense of OO programming.
I have tried various ways to solve problem.
Current approach is to house data concerning a single student examination in an instance of the class “Exam”.
This corresponds to a single line of the input file, plus subsequent calculations concerning other attributes of that instance only.
These attributes are populated with values during the while loop of readFile().
When the while loop ends, the three calculations that concern the entire collection of Exams (ie the entire academic class) are called.
A secondary question is:
Under the comment “Declare Attributes”, I’ve separated the attributes of the class into two subgroups:
Those that I think should be defined as class variables (with keyword static).
Those that I think should be defined as instance variables.
Could you guide me on whether I should add keyword static to those in first group.
A related question is:
Should the methods that perform calculations using the entire collection of instances be declared as static / class methods too?
When I tried that I then got similar errors when these tried to call instance methods.
Thanks.
PS: Regarding this forum:
I have enclosed the code with code blocks, but the Java syntax is not highlighted.
Perhaps it will change after I submit the post.
But if not I'd be happy to reformat it if someone can tell me how.
PPS: this is a homework assignment.
I have created all the code below myself.
The "homework" tag is obsolete, so I didn't use it.
Input File Name: "results.dat"
Input File Path: "C:/Users/ADMIN/Desktop/A1P3E1 Files/results.dat"
Input File Contents (randomly generated data):
Java File Name: "Exam.java"
Java Package Name: "a1p3e1"
Java Project Name: "A1P3E1"
Java File Contents:
java - Java main 方法是否启动了无限的while循环?
这个问题可能是一个非常新手的问题,但它让我很困惑。我正在研究 Java 网络,我对该方法的后端感到好奇main
。
我知道main
开始一个线程?因此,即使我有一个简单的“Helloworld”程序,在您关闭整个 IDE 或系统之前,线程仍然保持活动状态?
这是否意味着我可以在 main 方法中包含任何我想永远运行的任意代码(例如,心跳传感器检查或其他一些检查)。
谢谢
java - 从另一个类构造函数的主方法调用时出现“.class expected”错误
我正在制作一个创建具有某些属性的对象的基本程序,它工作正常,但我需要将它作为一个独立程序本身加载,所以我创建了另一个名为 Lanzador 的类,它从另一个类调用构造函数,以便它可以创建对象。
我是新手,所以我真的不知道我在这里做什么:
问题是我不知道如何真正做到这一点,因为它仍然给了我一个预期的“int.class”。
我应该怎么做才能在启动程序时让我输入属性(stirng、int 等)?
非常感谢。