In Visualforce, getter and setter are mandatory to reference variables from the custom controller or extension apex class.
1. Declare the variable with public scope.
2. User getter and setter.
Sample code:
public class ClassName() {
public String strVar { get; set; }
public ClassName() {
strVar = ‘Default Value’;
}
}