[英]Error: Main method not found in class TextBook, please define the main method as: public static void main(String[] args)
I try compiling it and it says no error. 我尝试编译它,它说没有错误。 But when i run the program it says: 但是当我运行程序时,它说:
Error: Main method not found in class TextBook, please define the main method as: public static void main(String[] args) 错误:在TextBook类中找不到主要方法,请将该主要方法定义为:public static void main(String [] args)
so when i add the public static void main
, the whole program has so many errors. 所以当我添加public static void main
,整个程序有很多错误。
import java.util.*;
public class Book
{
private int pageNum;
private String title;
Date today = new Date();
public Book(int pn, String name)
{
pageNum = pn;
title = name;
}
//Setter/Getter for pageNum
public int getpageNum()
{
return pageNum;
}
public void setpageNum(int pn)
{
pageNum = pn;
}
//Setter/Getter for Title
public String getTitle()
{
return title;
}
public void setTitle(String name)
{
title = name;
}
public void display()
{
System.out.println("Book.java" + "\nby Tyler " + today);
System.out.println("Book Title: " + title + "\nNumber of Pages: " + pageNum);
}
}
for TextBook.java 用于TextBook.java
public class TextBook extends Book
{
private String gradeLevel;
public TextBook(int pageNum, String title, String gl)
{
super(pageNum, title);
gradeLevel = gl;
}
//Setter/Getter for gradeLevel
public String getGradeLevel()
{
return gradeLevel;
}
public void setGradeLevel(String g)
{
gradeLevel = g;
}
public void display()
{
super.display();
System.out.println("Grade Level: " + gradeLevel);
}
}
for DemoBook.java 用于DemoBook.java
public class DemoBook
{
public static void main(String[] args)
{
Book oneBook = new Book(250, "Awesome Story");
TextBook oneTextBook = new TextBook(350, "Awesomer Story", "12");
oneBook.display();
oneTextBook.display();
}
}
You can only run java file with main
method. 您只能使用main
方法运行Java文件。
In your case, you can only run DemoBook.java
就您而言,您只能运行DemoBook.java
删除部件- for book.java
, for textbook.java
for DemoBook.java
或者将它们标记为注释并运行DemoBook
class Maximum_num {
public void num()
{
int x=5;
int y=6;
int z=7;
if(x>y)
{
if(x>z)
{
System.out.println("x is maximum number");
}
else
{
System.out.println("z is maximum number");
}
}
else if (y>z)
{
System.out.println("z is maximum number");
}
}
}
public class Calculate
{
public static void main(String [] args)
{
Maximum_num mn=new Maximum_num();
mn.num();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.