1 mar 2010

Haczyki


  1. Metoda o identycznej nazwie jak konstruktor ( np z void)
  2. Return char gdy metoda zwraca inta -> ok dozwolone
  3. Zwracanie null kiedy powinniśmy zwracać prymitywa.
  4. Do tablicy prowadzi referencja.
  5. Jeżeli stworzyłeś konstruktor z argumentami to już nie ma tego domyślnego bez argumentów
  6. Czy klasa abstrakcyjna ma konstruktor? -> Tak!
  7. Czy interfejs ma konstrutor? -Nie!
  8. Domyślny konstruktor ma taki sam access mod jak klasa!
  9. W konstruktorze nei może być jednocześnie this(..) i super(..)
  10. Metody static nie sa overriden lecz tylko po typie referencji!!

  11. instanceof tylko dla rferencji i klasy z tego samego drzewa dziedziczenia !

  12. long is illegal in switch statement!
  13. null isntance of [jakakolwiek kalsa] => false !! ( także pośrednio)
  14. [Dog object] instance of Cat => compilation error!
  15. argument byte not passing to method(Long)
  16. int x => wybierze Object x niż Integer... (var-arg)
  17. List nie możesz dodać Dog or Cat !!
  18. List poprawne!!
  19. List oznacza każdy rodzaj Listy!!!



//haczyki
String[] czyDozwolonyNull(){ return null; } //ok
int[] czyDozwolonyNullDlaPrymiTywa(){ return null; } //ok
}

abstract class CzykonstruktorMa {

public CzykonstruktorMa() {
}
}

class Konkret{
int dupeczka;

public Konkret() { }

/*To jest metoda a nie konstruktor!!!*/
public void Konkret(){}

public Konkret(int dupeczka) {
Konkret(); //metoda e nie konstruktor
this.dupeczka = dupeczka;
}
}


class Base{
int x; int y;

public Base(int x, int y) {
this.x = x; this.y = y;
}
}

//!class Extended extends Base{ } zonk bo
//nie ma domyślnego konstruktora

/*Teraz jest ok*/
class Extended extends Base{

public Extended(int x, int y) {
super(x, y);
}
}

Poliporfizm


  1. Tylko metody sąwywoływane dynamicznie ( po typie obiektu na który wskazuje referencja)
  2. Zmienne static i nonstatic nie są dynamicznie wybierane, wybieran są ząś po typie referencji!!
  3. Overloading nie po typie referencji!!
  4. Przy oveloading można dowolnie zmieniać modyfikator dostępu jak i zwracaną wartość.

instanceof


@Test
public void testInstanceOf() {

//assertTrue(null instanceof Object); false
//assertTrue(null instanceof String); false

//!!assertTrue(int instanceof Object); compilation Error
//@assertTrue(String instanceof Object); błąd kompilacji

//primitives
int x = 6;
//assertTrue(x instanceof Object); zonk :)
/**
* Wnioske:
* referencja instanceof Klasa
*/

int[] tab ={1,2,3};
assertTrue(tab instanceof Object); //ok
}




  1. Pisane tylko małymi literami
  2. Zasada: po lewej stronie referencja
  3. Zasada: po proawej stronie Klasa Name