Reputation: 17
I am writing a program that stretches over 3 different java files
I have defined a couple of variables using setter and getter commands in Pencil, that are appropriately being pulled and used in Pencilbox. How ever for some reason it is not able to locate one variable, the getBrand variable.
Pencil:
public String getbrand()
{
return brand;
}
public void setBrand(String brand){
this.brand=brand;
}
PencilBox:
public String toString(){
return type1.getColor() + " " + type1.getBrand + "$" + (type1.getPrice()*qty1) + "\n"
+ type2.getColor() + " " + type2.getBrand + "$" + (type2.getPrice()*qty2) + "\n$" + grandTotal();
}
But I keep getting these two errors:
symbol: variable getBrand location: variable type1 of type Pencil
and this:
symbol: variable getBrand location: variable type2 of type Pencil
Why is the public variable not accessible in the second program? getColor and getPrice worked with no problem. Can someone please explain?
Upvotes: 0
Views: 66
Reputation: 21
getBrand() is a method ,so you have to call it with paranthesis ()
type1.getBrand()
Upvotes: 0
Reputation: 291
You're missing brackets and should be lower case b e.g. try type1.getbrand() etc
Upvotes: 3