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
- Check class access permissions
- Check member access permissions
- Check scopes
- Check braces/brackets match up
- Check other syntax
- Check logic
Is there a more efficient way? Have I missed something?
Thanks