title: Creating an object inside an if statement
body: <p>I'm trying to make a simple program for a bank account. I have created a class called Bank to make and instance and in the main class, where the main method is, I have made an if statement which will create an instance of the class "Bank" depending on the conditions met. The problem is that I can use the instance methods, which is outside the if statement. I have created two constructors for the object class, one with a constructor method parameter and another method which doesnt take any parameters, which is the reason of using an if statement.</p>
  
  <pre><code> public static void start() {
        Scanner scanner = new Scanner(System.in);
  
        System.out.println("Welcome to your banking app!");
        System.out.println("What is your initial balance, enter below. If none enter : n");
        String choice = scanner.nextLine();
  
        if(choice.equals("n")){
             Bank account1 = new Bank();
        }
        else{
             System.out.println("Enter your initial balance :");
             double ibalance = scanner.nextDouble();
             Bank account1 = new Bank(ibalance);
        }
  
        System.out.println("Enter 1 to see balance Enter 2 to withdraw  Enter 3 to deposit money Enter 4 to close account Enter 5 to exit");
        choice = scanner.nextLine();
        double amount = 0.0; 
        if(choice.equals("1")){
             System.out.println("Balance is :" + account1.getBalance());
        }
  
        else if(choice.equals("2")){
             System.out.println("Enter the amount to withdraw");
             amount = scanner.nextInt();
             account1.withdraw(amount);
        }
  
        else if(choice.equals("3")){
             System.out.println("Enter the amount to deposit");
             amount = scanner.nextInt();
             account1.deposit(amount);
        }
  
        else if(choice.equals("4")){
             account1.close();
        }
  
        else if(choice.equals("5")){
             System.exit(0);
        }
   }
  </code></pre>