Letzte Tests vor der Prüfung

This commit is contained in:
2019-11-19 18:49:02 +01:00
parent c6a069facb
commit 27c32cf193
7 changed files with 69 additions and 0 deletions

View File

@@ -49,7 +49,13 @@ public class CastExceptions {
class OberCast { class OberCast {
public void method() throws IOException{ public void method() throws IOException{
Integer i;
long l2 = (int)12;
int i2 = 2;
i = (int)i2;
} }
} }

View File

@@ -1,5 +1,7 @@
package org.eidecker.oca8lernen.general; package org.eidecker.oca8lernen.general;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class InterfaceWithFields implements T1, T2 { public class InterfaceWithFields implements T1, T2 {
@@ -18,6 +20,8 @@ public class InterfaceWithFields implements T1, T2 {
interface T1 { interface T1 {
int VALUE = 99; int VALUE = 99;
int VALUE_T1 = 1; int VALUE_T1 = 1;
default int getValue() {return VALUE;}
} }
interface T2 { interface T2 {
@@ -31,11 +35,15 @@ interface T2 {
class Tester { class Tester {
@Test
public void interfaceTest() { public void interfaceTest() {
InterfaceWithFields interfaceWithFields = new InterfaceWithFields(); InterfaceWithFields interfaceWithFields = new InterfaceWithFields();
assertEquals(99, ((T1)interfaceWithFields).VALUE); assertEquals(99, ((T1)interfaceWithFields).VALUE);
assertEquals(98, ((T2)interfaceWithFields).VALUE); assertEquals(98, ((T2)interfaceWithFields).VALUE);
T1 t1 = new InterfaceWithFields();
System.out.println(t1.getValue());
assertEquals(1, interfaceWithFields.VALUE_T1); assertEquals(1, interfaceWithFields.VALUE_T1);
assertEquals(2, interfaceWithFields.VALUE_T2); assertEquals(2, interfaceWithFields.VALUE_T2);
} }

View File

@@ -202,6 +202,11 @@ class PrimitiveOverloading {
return VARIANTE_BYTE; return VARIANTE_BYTE;
} }
public String neuerVersuch(byte l) {
System.out.println("long");
return "long";
}
} }
class PrimitiveOverloadingTester { class PrimitiveOverloadingTester {
@@ -229,7 +234,30 @@ class PrimitiveOverloadingTester {
// Primitiv, nicht vorhanden, auch kein Wrapper // Primitiv, nicht vorhanden, auch kein Wrapper
assertEquals(VARIANTE_INT, primitiveOverloading.overloadMe((short) 1)); 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;
} }
} }

View File

@@ -131,6 +131,8 @@ interface MySuperInterface extends Serializable, ThreadFactory {
default void m1() { default void m1() {
} }
public abstract void my();
} }
interface MyOtherSuperInterface { interface MyOtherSuperInterface {

View File

@@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test;
public class Oberklasse { public class Oberklasse {
static protected String feldInOberklasse;
public final void publicMethode() { public final void publicMethode() {
System.out.println("Public"); System.out.println("Public");
} }

View File

@@ -9,6 +9,17 @@ public class StaticSichtbarkeit {
Ober ober = new Unter(); Ober ober = new Unter();
ober.methode2(ober); // Ober, da zur Compilezeit ausgewählt (Bei Überladen würde nur die Signatur gewählt!) 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);
} }
} }

View File

@@ -3,9 +3,21 @@ package org.eidecker.oca8lernen.lastminute.hilfspackage;
import org.eidecker.oca8lernen.lastminute.Oberklasse; import org.eidecker.oca8lernen.lastminute.Oberklasse;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.IOException;
public class KlasseInEinemAnderenPackage extends Oberklasse { public class KlasseInEinemAnderenPackage extends Oberklasse {
protected String feldInOberklasse;
void privateMethode() { void privateMethode() {
try {
// anotherOne();
} catch (Exception e) {
}
}
void anotherOne() throws IOException {
} }