class A { public virtual int M() => 0; }
class B : A { public override int M() => 1; }
A a = new B();
Console.WriteLine(a.M());
int prop;
int Prop => prop;
throw...
class A { public virtual int M() => 0; }
class B : A { public override int M() => 1; }
B b = (B)(new A());
Console.WriteLine(b.M());
Ktery delegat lze pouzit na implementaci porovnani dvojice studentu pro realizaci razeni pole: Student[] pole?
class A { public virtual int M() => 0; }
class B : A { public int M() => 1; }
A a = new B();
Console.WriteLine(a.M());
try {
...
}
Vyberte nejvhodnejsi variantu:
class A { public int M() => 0; }
class B : A { public int M() => 1; }
B b = new B();
Console.WriteLine(b.M());
public static void Method(ref string s) {
s = "World";
}
...
string s = "Hello";
Method(ref s);
Console.WriteLine(s);
Vyberte zkompilovatelny kod:
interface IA { int I { get; set; } }
class A : IA {}
...
A a = new A();
a.I = 123;
typeof(List <int>) == typeof(IList<string>)
int prop;
int Prop {
...
}
Hodnotove datovy typy jsou:
int prop;
int Prop {
get => Prop;
set => Prop = value;
}
Vyberte spravne pojmenovani:
class A { public int M() => 0; }
class B : A { public new int M() => 1; }
A a = new B();
Console.WriteLine(a.M());
private int?[]? arry;
class A { void M() {} }
...
A a = new A();
a.M();
delegate int CounterCallback();
...
static int Adder() { return 1; }
...
CounterCallback? cc = null;
cc += Adder;
cc += Adder;
cc += Adder;
Console.WriteLine(cc());
Vyberte udalost
public static class ExtString extends String {
}
public static <T extends String> T method(T value) {
return (T)(value + " ");
}
public static void main(String []args){
method(new ExtString());
}
public static <T extends String> T method(T value) {
return (T)(value + " ");
}
public static void main(String []args){
method("Hello");
}
public static <T> T method(T value) {
return value + "";
}
public static void main(String []args){
method("Hello");
}
public class First<T super Comparable<T>>{}
public class First<T> {
public void method(T obj) {
T[] ary = (T[])new Object[10];
ary[0] = obj;
public class First<T> {
public void method() {
T[] ary = new Object[10];
public class First<T> {
public void method() {
T[] ary = new T[10];
Genericita v Javě umožňuje použití
public class List<T> { private T[] data; }
public class List { private Object[] data; }
Jeden znak v UTF-8 zabírá
Které třídy/rozhraní nabízejí možnost načíst textový soubor a API přímo vrací načtený String (slovo, řádek, celý soubor, ...)
Javovské try-with-resources
var unknownDatatype = ~~~"-"[-~-0];
class A { void M() {}}
A a = new A();
a.M();
var unknownDatatype = ~-~"-"[~-~0];
class A: A {}
int prop;
int Prop {
get;
set => prop = value;
}
Vyberte platné varianty
Створюйте онлайн-тести
для контролю знань і залучення учнів
до активної роботи у класі та вдома