简体   繁体   中英

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 must extend 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 "test" is not an inner class of "QNA". The class "test" should be an inner class of "QNA" or it should be in its own file. And you need to target class "test", not class "QNA".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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