我尝试编译它并且没有错误。但当我运行程序时,它说:
错误:在TextBook类中找不到主要方法,请定义main 方法为:public static void main(String [] args)
所以当我添加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
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
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();
}
}
答案 0 :(得分:0)
您只能使用main
方法运行java文件。
在您的情况下,您只能运行DemoBook.java
答案 1 :(得分:0)
删除部分 - for book.java
,for textbook.java
for DemoBook.java
或将其标记为评论并运行DemoBook
答案 2 :(得分:0)
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();
}
}