我嘗試在使用NetBeans IDE的java中製作一個簡單的類。每當我嘗試執行它時,它都會給出這樣的警告:「從靜態上下文引用的非靜態變量」。任何人都可以告訴我爲什麼會發生,以及如何解決它。提前Thanx。從靜態上下文引用的非靜態變量
public class HW3Q4 {
class Payment{
private double amount_payment;
public void set_amount(double amount){
amount_payment = amount;
}
public double get_amount(){
return amount_payment;
}
public void paymentDetails(){
System.out.println("The amount of the payment is: "+amount_payment);
}
}
public static void main(String[] args) {
// TODO code application logic here
Payment p1 = new Payment();
p1.set_amount(34000.00);
p1.get_amount();
p1.paymentDetails();
}
}
'付款p1 =新HW3Q4()。新付款();'由於付款是內部類 – 2014-10-29 11:05:27
或者,它看起來像你想'靜態類付款'。 – bcsb1001 2014-10-29 11:06:28
'class Payment'應聲明爲'static'。 – 2014-10-29 11:07:04