Originally posted by michelle hou:
class Test {
int y=1;
static int a=6;
// Test() passed into int a=6
Test() {
this(a);
}
//Test(a) sign Test(int x), x=a=6, x>y true
//if y=7 not 1, x>y false, output will be 22
Test(int x) {
if ( x > y )
a = y*2;
else
a = y*3;
a++;
}
public static void main(String [] args) {
Test t = new Test();
System.out.println(a);
}
}
>>Thanks Suneeta question, let me learn lot
Originally posted by Trevor Green:
The code fragment below is provided:
1. class Test{
2. public static void main(String [] args){
3. aMethod();
4. }
5.
6. static void aMethod(){
7. try{
8. System.out.println("abcd");
9. return;
10. } finally {
11. System.out.println("1234");
12. }
13. }
14. }
This compiles.
My queries are
1) Why does it not complain about a return on line 9 when the method is null? (Is this to do with the fact the compiler looks to see what is returned - in this case nothing - and so the presence of null works like a break?)
2) Why doesn't it complain about a try without a catch?
What are the rules about including keywords in the code without actually using them?