tags:

views:

26

answers:

0

Hello,

When practising mock exams (for Java certification, but this question could apply to any language), I often look at the code in question and struggle to find somewhere to start

Often, one of the answers may be "code does not compile", therfore you need to carefully examine the source code, and a good logical structure of doing this is required

Given the following, how would you approach it, what would you look for first?

    class C
    {
       static int s;

      public static void main(String a[])
      {
         C obj=new C();
         obj.m1();    
         System.out.println(s);
      }

      void m1();
      {
         int x=1;
         m2(x);
         System.out.println(x+"");
      }

      void m2(int x)
      {
         x=x*2;
         s=x;
      }
   }

So far my approach is the follows

  1. Check class access permissions
  2. Check member access permissions
  3. Check scopes
  4. Check braces/brackets match up
  5. Check other syntax
  6. Check logic

Is there a more efficient way? Have I missed something?

Thanks