3 Replies Latest reply: Mar 26, 2013 10:34 PM by 967983 RSS

    One compiles but another doesn't

    967983
      There is almost no difference between code that compiles and the code that doesn't compile

      The code that compiles:
      public class FinalVariableExample 
      {
           public static void main(String[] args) {
                final int hoursInDay;
                boolean b=true;
                if(true)
                {
                     hoursInDay=25;
                     System.out.println("Inside if");
                }
                System.out.println("Hours in 5 days = " + hoursInDay * 5);
           }
      }
      The code that doesn't compile
      public class FinalVariableExample 
      {
           public static void main(String[] args) {
                final int hoursInDay;
                boolean b=true;
                if(b==true)
                {
                     hoursInDay=25;
                     System.out.println("Inside if");
                }
                System.out.println("Hours in 5 days = " + hoursInDay * 5);
           }
      }
      There is just one difference between the two codes but still one does not make past the compiler. Why is it?

      Edited by: 964980 on Mar 26, 2013 2:55 AM