Forgive me if I have not understood your problem correctly :). It seems to me that perhaps it's easier to wrap up your 'final' variables into an immutable class. Then create an instance of such a class in 'condition1'. Here's what I mean...
import java.util.Scanner;
import java.util.Calendar;
public class ImmutableHourMinute {
private final int a;
private final int b;
public ImmutableHourMinute(final int $a, final int $b){
this.a = $a;
this.b = $b;
}
public int getA() {
return a ;
}
public int getB() {
return b;
}
public static void main(String... args){
// Requirements:
// 1. Hour and minute are set at condition == 1;
// 2. Hour and minutes must never be changed.
System.out.println("Please type 'start':");
Scanner scanner = new Scanner(System.in);
ImmutableHourMinute hourAndMinute = null; // Can be initialized properly later
while(!scanner.nextLine().equals("quit")){
System.out.println("Please enter condition (1 or 2):");
int condition = scanner.nextInt();
if(condition == 1){
Calendar rightNow = Calendar.getInstance();
int a = rightNow.get(Calendar.HOUR);
int b = rightNow.get(Calendar.MINUTE);
System.out.println(String.format("(Creating ImmutableHourMinute(a=%1$d, b=%2$d)", a, b));
hourAndMinute = new ImmutableHourMinute(a, b);
}else if (condition == 2){
display(hourAndMinute.getA() + hourAndMinute.getB());
}
System.out.println("Please enter condition (1 or 2):");
}
}
private static void display(final int displayValue){
System.out.println(String.format("Displaying the time set in condition 1 :%1$d", displayValue));
}
}
And here is a sample of the output:
$ java ImmutableHourMinute
Please type 'start':
start
Please enter condition (1 or 2):
1
(Creating ImmutableHourMinute(a=9, b=56)
Please enter condition (1 or 2):
Please enter condition (1 or 2):
2
Displaying the time set in condition 1 :65
note : such and immutable class already exists(if you're using Java SE 8)...
java.time.LocalDateTime