-2
class  Bill{
    int billid;
    // **setter for the variable**
    public void setbillid(int i){
        billid=i;
    }

    // **getter for the variable**
    public int getbillid(){
        return billid;
    }
}
public class Main{
    public static void main(String[] args) {
        // **This below is generating the error**  
        Bill b = new Bill();
        System.out.println(b.getbillid);
    }
}   

symbol: variable setbillid

location: variable b of type Bill

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

2 Answers2

1

the error message is wrong - it should be

symbol: variable getbillid

and not setbillid

:-)


You can choose:

use the method: System.out.println(b.getbillid());

or the variable (not recommended): System.out.println(b.billid);
(assuming it is accessible)


Anyway, since the setter was not called, it will have its initial value: 0\

I would like to recommend to use the usual naming conventions (getBillId, setBillId, billId,...)

0
System.out.println(b.getbillid());

getbillid() is a method that returns Billid. The right way to call a method is objectName.methodName() and variable is objectName.variableName.

XO56
  • 332
  • 1
  • 12