为什么这段java代码没有运行?我正在尝试创建类,然后从类中创建对象。代码未编译,它说**公共类型应用程序必须在其自己的文件中定义**请帮助。
public class Book{
public String title;
public String author;
public int numPages;
}
public class App
{
public static void main(String [] args)
{
Book book1 = new Book();
book1.title = "Harry Potter";
book1.author = "JK Rowling";
book1.numPages = 400;
System.out.println(book1.title);
Book book2 = new Book();
book2.title = "Lord of the Rings";
book2.author = "JRR Tolkien";
book2.numPages = 300;
System.out.println(book2.title);
}
}
白板的微信
相关分类