[英]java program have only one public class should main method only be part of that public class then any other class of that program?
program running fine when main method is inside class QNA but give error when defined inside class test error: Main method not found in class QNA, please define the main method as: public static void main(String[] args) or a JavaFX application class必須擴展 javafx.application.Application
import java.util.Scanner;
public class QNA{
Scanner scan= new Scanner(System.in);
private int a;
private int b;
public void get_value(int x,int y)
{
a=x;
b=y;
}
public int set_data()
{
int a=scan.nextInt();
return a;
}
public int set1_data()
{
int b=scan.nextInt();
return b;
}
}
class test
{
public static void main(String[] args) {
QNA q1= new QNA();
int p=q1.set_data();
int p1=q1.set1_data();
int c=p+p1;
System.out.println(c);
}
}
Class“測試”不是“QNA”的內部 class。 class“測試”應該是“QNA”的內部 class 或者它應該在自己的文件中。 而且您需要針對 class “測試”,而不是 class “QNA”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.