Print语句给出“找不到符号”的消息

时间:2011-11-13 14:23:29

标签: java netbeans

我正在玩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 %s\n", 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语句抛出一条消息“找不到符号”。

知道问题可能是什么?

2 个答案:

答案 0 :(得分:1)

错误即将发生,因为您在whatDay类中对println的调用未包含在方法中。

答案 1 :(得分:1)

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

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

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

顺便说一句:你应该用大写字母开始上课。

享受Java的乐趣:)

相关问题