9 mar 2010

Overriding i overloading

Following code fragment is given (Java 5):

1: class Human {
2:
Human getIt() {
3:
return this;
4:
}
5:
}
6:
7:
class Worker extends Human {
8:
// insert a single method here
9:
}

Which of the following methods would compile if inserted at line 8

Human getIt() { return this; }
Worker getIt() { return this; }
Object getIt() { return this; }
int getIt() { return 1; }
int getIt(int x) { return 1; }
Object getIt(int x) { return this; }


Try catch finally



  1. A try block can be followed either by a catch block or a finally block, or both.

    A catch block must always be associated with a try block.

    A finally block can never stand on its own (that is, without being associated with try block).

Haczyki v2


if(20%4){} //zonk bo wynikiem jest int!!


String s = null; /* Nie bedzie NullPointerException!!!!!!!!!*/
String result = s != null && s.equals("test") ? "yes" : "no";

  1. Kwestia || i | w jednym ifie + kwsestia && i & w jednym ifie
  2. Jeśli casy w switchu się powtórzą to! => compilation error!!!!!!!!!