| CIT 591 Second Quiz Fall 2001, Dave Matuszek |
Name Answer key
|
i is an int variable and d is
a double variable. Answer each of the following eight questions
with YES or NO.
| Is this a syntax error? | Could this cause a runtime error? | |
i = 3.5 * d; |
YES | NO |
d = 3.5 * i; |
NO | NO |
i = (int) (3.5 * d); |
NO | YES |
d = (double)(3.5 * i); |
NO | NO |
0x77 hex 0 octal 047 octal77 decimal
class Test {
public static void main(String args[]) {
int foo = 5;
foo(foo);
System.out.println(foo);
}
static void foo(int bar) {
System.out.println(bar++);
}
}
foo? foo foo? bar foo? (Besides int!) local,
or method foo were
not declared static? syntax
error (reference to non-static method in static context)System.out.print will print any object, but the result
may not be useful. What method must you define in order to control how
an object is printed? public String toString( )