当前位置: 首页 > 知识库问答 >
问题:

错误:课堂课本中找不到Main方法,请将Main方法定义为:public static void Main(String[]args)

楮乐邦
2023-03-14

我试着编译它,它说没有错误。但当我运行程序时,它说:

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);
    }
}
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);
    }

}
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();
    }
}

共有1个答案

罗鸿福
2023-03-14

您只能使用main方法运行java文件。

在您的情况下,只能运行demobook.java

 类似资料: