Inheritance & Interfaces Flashcards

1
Q

Předpis abstraktní třídy s metodou

A

public abstract class MyClass {
public abstract void m();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Co je abstraktní třída/metoda?

A

Třída obsahující aspoň jednu abstraktní metodu
Metoda bez implementace
Dědící třída ji musí implementovat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Kolik smí třída rozšířit tříd a implementovat interface?

A

Rozšířit 1, implementovat kolik chce

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Předpis interface s metodou

A

public interface Ifc {
public void method();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Druhy inner class

A

Static - pro tridu
Member - pro instanci
Local - v metode
Anonymous - inline implementace / rozsireni ifc/class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Modifikatory viditelnosti tridy

A

private - jen ja a moje inner classy
default (=nepise se) - vsichni v mem pkg
protected - vsichni v mem pkg a moji potomci
public - vsichni (v modulu)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Jak se vytvori instance staticke tridy Nested bydlici ve tride Outer

A

Outer.Nested nested = new Outer.Nested();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Trida Outer obsahujici statickou tridu Nested.
Kdo vidi private veci tridy Nested?
Jak lze takovou tridu s privatnim konstr. instanciovat?

A

Nested, Outer
Outer.Nested x = Outer.createNestedInstance();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Trida Outer obsahujici statickou tridu Nested.
Kdo vidi private veci tridy Outer?

A

Outer, Nested
Outer, Nested take, ale jen staticke

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

vytvareni member inner class

A

nejprve se musi vytvorit instance outer class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

local inner class - hranice existence, jake promenne muze pouzit

A

existuje jen uvnitr metody
muze pouzit promenne a parametry metody, jen pokud jsou final / efektivne final

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Co je efektivne finalni promenna?

A

Hodnota se priradi jednou a nikdy se nezmeni

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Co je functional interface?
Syntax

A

Ma prave jednu metodu k implementaci
Muze obsahovat i dalsi cleny
nepovinna anotace nad ifc: @FunctionalInterface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Anonymni trida - syntax

A

var anonymousClass = new ParentClass/Ifc() {
@Override
//method defitintion
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Anonymni trida - inline syntax pro func. ifc: scitani

A

var anonymousClass = (a, b) -> a+b;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Co je default implementation metoda v ifc?
Co je jeji opak?
Co muze udelat potomek? (3)

A

Je to metoda, ktera ma implementaci.
Abstraktni metoda
Nic - zdedi ji
Prepsat - vlastni implementace (povinne, pokud je ve vice mych ifc)
Deklarovat - jako abstraktni, jeho potomek ji musi prepsat

17
Q

defaultni metoda - syntax

A

(public) (default) void method() { /* impl */ }

18
Q

Co je lambda?
Syntax
- nechci menit hodnotu parametru v tele a vracim hodnotu
- vracim hodotu jedinym radkem

A

Inline implmentace funkcionalniho interface
(x, final String y, final var z) -> { action(x, y, z); return 0; }
(x, y, z) -> 0;

19
Q

Method reference - syntax (3)

A

MyClass::method
myInstance::method
MyClass::new (=konstruktor)

20
Q

public class MyClass {
public int method(String x) { return 0; }
}
preved na method reference
preved na lambdu

A

MyClass::method
(x) -> 0

21
Q

Nested member class - syntax

A

public class Outer {
private/public class Inner {

}
}

22
Q

Nested static class - syntax

A

public class Outer {
private/public static class Inner {
….
}
}

23
Q

Local inner class - syntax

A

public void method(final var p, var q) {
class Inner {
…. // p je videt, q neni
}
Inner inner = new Inner();
}

24
Q

Interface - jaka klicova slova jsou implicitni pro metodu v ifc, tedy byly vynechany?
void method();

A

public abstract

25
Q

Staticka metoda v ifc

A

Zustava parentovi, vola se:
var result = Ifc.method();

26
Q

Pri implementaci metody co je dovoleno?
prepsat public na private (zuzit access)
prepsat private na public (rozsirit access)

A

prepsat private na public (rozsirit access)

27
Q

Syntax interface - IfcChild, ktere dedi z IfcParent

A

public interface IfcChild extends IfcParent { }

28
Q

Stejna metoda v mem rodici a ifc.
Ktera plati?

A

V rodici (superclass)

29
Q

Stejna default metoda v mem ifc i v jeho nadrazenem ifc
Ktera plati?

A

blizsi ifc

30
Q

Stejna default metoda ve dvou mych ifc
Ktera plati?

A

Zadna, musim ji prepsat.

31
Q

public void method() {…}

@Override
public void method() throws Exception { … }

Lze mit pri prepsani jinou vyjimku nez rodic?

A

Jo

32
Q

Can interface have instance field?

A

No

33
Q

Can interface have final method?

A

No

34
Q

Prepsani metody. V cem se muze lisit navratovy typ?

A

Muze byt subclass navratove hodnoty z puvodni metody