| CIT591 Final Exam Fall, 2002 |
Name_________________________________________ |
System.out.println
statement. Then fill in the following table, telling (1) the simplest
possible way to print the variable, and (2) what value will be printed for
it. If a variable cannot be accessed, tell why.
public class Major {
int a = 1, b = 2, c = 3;
Extra extra = new Extra();
public static void main(String args[]) {
int b = 4, d = 5;
Minor minor = new Minor(b);
minor.printAll();
}
}
class Minor extends Major {
int c = 6, e = 7;
static int f = 8;
Minor(int param) { b = e = param; }
void printAll() {
System.out.println( expression from table below );
}
}
class Extra {
int f = 9;
Extra() { f = 10; }
class Inner { int g = 11; }
Inner inner = new Inner();
}
|
| Variable | Simplest expression to access variable | Value |
a in Major |
||
b in Major |
||
b in main |
||
c in Major |
||
c in Minor |
||
d in main |
||
e in Minor |
||
f in Minor |
||
f in Extra |
||
g in Inner |
1 interface Inter { 2 int number(); 3 } 4 abstract class Abs { 5 static int foo = 12; 6 int number() { return 5; } 7 abstract int ace(); 8 } 9 final class Sub extends Super { 10 Sub(int bar) { foo = bar; } 11 public int number() { return 10; } 12 int ace() { return 13; } 13 int dubble(int i) { return 2 * i; } 14 } 15 public class Super extends Abs implements Inter { 16 public int number() { return 11; } 17 public static void main(String args[]) { 18 Super s1 = new Super(); 19 Super s2 = new Sub(16); 20 System.out.println( ); 21 } 22 int twice(int x) { return 2 * x; } 23 public int thrice(int x) { return 3 * x; } 24 int ace() { return 1; } 25 String dubble(String s) { return s + s; } 26 }
| s1.ace() | s2.ace() | s1.foo | s2.foo |
| s1.twice(3) | s2.twice(3) | s1.dubble(6) | s2.dubble(7) |
| s1.number() | s2.number() | s1.dubble("8") | s2.dubble("9") |