打印语句给出"cannot find symbol"消息



我正在使用java,遇到了以下问题:

我有以下类

class Training{
    public static void main(String[]args){
       book firstBook = new book("Hamlet","William Shakespeare");
       book secondBook = new book("Heart of Darkness", "Joseph Conrad");
       book thirdBook = new book("Database Design","M Hernandez");
       System.out.println();
       System.out.println("Total number of books is " + book.noOfBooks + "n");
       System.out.println();
    }
}
public class book {
    private String name;
    private String author;
    private int id;
    public static int noOfBooks = 0;
    public book(String n, String a){
        name = n;
        author = a;
        id = ++noOfBooks;
        System.out.printf("The book you've just created is %sn", this);
    }
    public String toString(){
        return String.format("%s by %s id %d", name, author, id);
    }
    public String getName(){
        return name;
    }
    public String getAuthor(){
        return author;
    }
    public int getID(){
        return id;
    }
}
public class whatDay {
    System.out.println();
}

NetBeans在whatDay类的print语句中抛出一个消息'cannot find symbol'。

你知道是什么问题吗?

问题是System.out.println();,因为您没有将其放入方法中。

尝试将System.out.println()放入一个方法中。例如:

public class WhatDay {
    // Constructor
    public WhatDay() {
        System.out.println()
    }
}

顺便说一下:你应该用大写字母开始类名。

祝你Java玩得开心!)

出现错误是因为在whatDay类中对println的调用没有包含在方法中

相关内容

  • 没有找到相关文章

最新更新