Letzte Tests vor der Prüfung
This commit is contained in:
@@ -49,7 +49,13 @@ public class CastExceptions {
|
||||
class OberCast {
|
||||
|
||||
public void method() throws IOException{
|
||||
Integer i;
|
||||
|
||||
long l2 = (int)12;
|
||||
|
||||
int i2 = 2;
|
||||
|
||||
i = (int)i2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.eidecker.oca8lernen.general;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class InterfaceWithFields implements T1, T2 {
|
||||
@@ -18,6 +20,8 @@ public class InterfaceWithFields implements T1, T2 {
|
||||
interface T1 {
|
||||
int VALUE = 99;
|
||||
int VALUE_T1 = 1;
|
||||
|
||||
default int getValue() {return VALUE;}
|
||||
}
|
||||
|
||||
interface T2 {
|
||||
@@ -31,11 +35,15 @@ interface T2 {
|
||||
|
||||
class Tester {
|
||||
|
||||
@Test
|
||||
public void interfaceTest() {
|
||||
InterfaceWithFields interfaceWithFields = new InterfaceWithFields();
|
||||
assertEquals(99, ((T1)interfaceWithFields).VALUE);
|
||||
assertEquals(98, ((T2)interfaceWithFields).VALUE);
|
||||
|
||||
T1 t1 = new InterfaceWithFields();
|
||||
System.out.println(t1.getValue());
|
||||
|
||||
assertEquals(1, interfaceWithFields.VALUE_T1);
|
||||
assertEquals(2, interfaceWithFields.VALUE_T2);
|
||||
}
|
||||
|
||||
@@ -202,6 +202,11 @@ class PrimitiveOverloading {
|
||||
return VARIANTE_BYTE;
|
||||
}
|
||||
|
||||
public String neuerVersuch(byte l) {
|
||||
System.out.println("long");
|
||||
return "long";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class PrimitiveOverloadingTester {
|
||||
@@ -229,7 +234,30 @@ class PrimitiveOverloadingTester {
|
||||
// Primitiv, nicht vorhanden, auch kein Wrapper
|
||||
assertEquals(VARIANTE_INT, primitiveOverloading.overloadMe((short) 1));
|
||||
|
||||
primitiveOverloading.neuerVersuch((char)12);
|
||||
|
||||
OverloadMe2 overloadMe2 = new OverloadMe2();
|
||||
// overloadMe2.one(1, 1);
|
||||
|
||||
overloadMe2.two(new Integer(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class OverloadMe2 {
|
||||
|
||||
public int one(double d, int i) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int one(int d, double i) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int two(Long i) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -131,6 +131,8 @@ interface MySuperInterface extends Serializable, ThreadFactory {
|
||||
default void m1() {
|
||||
|
||||
}
|
||||
|
||||
public abstract void my();
|
||||
}
|
||||
|
||||
interface MyOtherSuperInterface {
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Oberklasse {
|
||||
|
||||
static protected String feldInOberklasse;
|
||||
|
||||
public final void publicMethode() {
|
||||
System.out.println("Public");
|
||||
}
|
||||
|
||||
@@ -9,6 +9,17 @@ public class StaticSichtbarkeit {
|
||||
Ober ober = new Unter();
|
||||
ober.methode2(ober); // Ober, da zur Compilezeit ausgewählt (Bei Überladen würde nur die Signatur gewählt!)
|
||||
|
||||
System.out.println(ober.s);
|
||||
|
||||
String a = "";
|
||||
a += "Welt";
|
||||
// a -= "Welte";
|
||||
String b = null;
|
||||
System.out.println(b instanceof Object);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,21 @@ package org.eidecker.oca8lernen.lastminute.hilfspackage;
|
||||
import org.eidecker.oca8lernen.lastminute.Oberklasse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class KlasseInEinemAnderenPackage extends Oberklasse {
|
||||
|
||||
protected String feldInOberklasse;
|
||||
|
||||
void privateMethode() {
|
||||
try {
|
||||
// anotherOne();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void anotherOne() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user