On the subject of the exam, I saw a few things that I didn't see in the practice and might be useful to enthuware. I won't copy the exam questions but I'll give examples like the exam.
1. String s = (String) (1+2)
2. What change would make the following compile?
Code: Select all
abstract class A {
protected void foo() {}
abstract void bar();
}
class B extends A {
private void foo() {} // line 1
private void bar() {} // line 2
}
3. This is similar to a practice exam question, except it has a static variable and none of the answer options were "this won't compile". Not sure what to do about that.
Code: Select all
class X {
static int someVar;
public int foo() {
int b, h;
if (someVar == 0) {
b = 2;
h = 3;
}
return b * h; // local variable may not have been initialized
}
}
5. Which of these compile?
- a class with a private constructor
- an abstract class with a constructor
- a final abstract class
- a class with protected static final int i = 0;
- a private class
6.
Code: Select all
class Foo{
String s = "";
public boolean equals(Foo f) {
return s.toString().equalsIgnoreCase(f.s.toString());
}
}
public class TestClass extends Foo{
public static void main(String[] args){
Foo f = new Foo();
f.s = "Hello";
System.out.println(f.equals("Hello")); // prints: false
}
}