|  Home |  Back |  Contents |  Next | 
| 
int addTwoNumbers( int a, int b ) {
    return a + b;
}
 | 
| sum = addTwoNumbers( 5, 7 ); | 
| 
add( a, b ) {
    return a + b;
}
 | 
| 
foo = add(1, 2);
print( foo ); // 3
foo = add("Oh", " baby");
print( foo ); // Oh baby
 | 
| 
// foo() and bar() are synchronized as if they were in a common class
synchronized foo() { }
synchronized bar() { }
 | 
| 
a = 1;
anotherMethod() { ... }
foo() {
    print( a );
	a = a+1;
	anotherMethod();
}
// invoke foo()
foo();      // prints 1
print( a ); // prints 2
 | 
| 
a = 1;
foo() {
	a = a + 1; // a is defined in parent scope
	b = 3;     // undefined, defaults local scope
	int c = 4; // declared local scope
}
// invoke foo()
print( a ); // prints 2
print( b ); // ERROR! b undefined
print( c ); // ERROR! c undefined
 | 
| 
foo() {
	var a = 1;
}
foo();
print( a ); // ERROR! a is undefined!
 | 
| 
foo() {
	this.a = 1;
}
foo();
print( a ); // ERROR! a is undefined!
 | 
| 
int a = 42;
foo() {
    int a = 97;
    print( a );
    print( super.a );
}
foo();  // prints 97, 42
 | 
|  Home |  Back |  Contents |  Next |