Accessability/Visability Private
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"
Code :
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.
Code :
public class A
{
private int num;
// the getter method
public int getNum()
{
return this.num;
}
}