user3663055
user3663055

Reputation: 17

Java program not able to find public variable stored in another class

I am writing a program that stretches over 3 different java files

  1. pencil.java
  2. pencilbox.java
  3. schoolbad.java

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

Answers (3)

Akitha_MJ
Akitha_MJ

Reputation: 4294

Correct with this and try

type1.getBrand() 

Upvotes: 0

Abhishek Yadav
Abhishek Yadav

Reputation: 21

getBrand() is a method ,so you have to call it with paranthesis ()

type1.getBrand()

Upvotes: 0

Pete Hendry
Pete Hendry

Reputation: 291

You're missing brackets and should be lower case b e.g. try type1.getbrand() etc

Upvotes: 3

Related Questions