1

「静的コンテキストから参照できない非静的変数」に関するエラーが 17 個あるため、以下のコードをコンパイルできません。常にthisキーワードを指しています。

package MyLib;
import java.util.*;

class Book {

static int pages;
static String Title;
static String Author;
static int status;
static String BorrowedBy;
static Date ReturnDate;
static Date DueDate;

public static final int
    BORROWED = 0;

public static final int
    AVAILABLE = 1;

public static final int
    RESERVED = 2;

    //constructor
public Book ( String Title, String Author, int pp) {
    this.Title = Title;
    this.Author = Author;
    this.pages = pp;
    this.status = this.AVAILABLE;
}

public static void borrow(String Borrower/*, Date Due*/){
    if (this.status=this.AVAILABLE){
        this.BorrowedBy=Borrower;
        this.DueDate=Due;
    
    }
    else {
    
        if(this.status == this.RESERVED && this.ReservedBy == Borrower){
            this.BorrowedBy= Borrower;
            this.DueDate=Due;
            this.ReservedBy="";
            this.status=this.BORROWED;
        }
    }
}
4

3 に答える 3

2

一文で、

静的メソッド/静的初期化子などの静的コンテキスト内で「このキーワード」を使用することはできません。

于 2013-07-23T15:27:18.623 に答える