This is part of a assignment, I was instructed to make a variable in a class 'A' private. Class 'B' extends class 'A' and class B uses the variable in class A that I declared private. Now I am going to receive an error message until I deal with the usage of this variable.
How can a class B object get access to this private variable of class A without changing the accessibility/visibility of the variable?
Here is a snippet of the code, the variable is "text"
tokenizer = new StringTokenizer(text, " ");
Re: Accessability/Visability Private
Are you allowed to modify class A? If so, I would add what is known as a "getter" method. In essense, it simply returns the value of the variable you want.
public class A
private int num;
// the getter method
public int getNum()