Anki Deck Changes

Commit: 460deb80 - can eprog fix it?

Author: lhorva <lhorva@student.ethz.ch>

Date: 2026-01-29T00:47:27+01:00

Changes: 9 note(s) changed (0 added, 9 modified, 0 deleted)

ℹ️ Cosmetic Changes Hidden: 4 note(s) had formatting-only changes and are not shown below • 4 mixed cosmetic changes

Note 1: ETH::1. Semester::EProg

Deck: ETH::1. Semester::EProg
Note Type: Horvath Cloze
GUID: gc|oK]2yr^
modified

Before

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
We cannot override attributes inside a subclass they are shadowed.

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
We cannot override attributes inside a subclass they are shadowed.

After

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
We cannot override attributes inside a subclass, they are shadowed.

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
We cannot override attributes inside a subclass, they are shadowed.

class Animal {
  String name = "Animal";
  String getName() {
    return "Animal";
  }
}

class Dog extends Animal {
  String name = "Dog"; // Shadows Animal.name (doesn't override it)
  @Override String getName() { return Dog"; } // Overrides Animal.getName()
}

Animal a = new Dog();
System.out.println(a.name); // "Animal" — field access uses static type
System.out.println(a.getName()); // "Dog" — method call uses dynamic type
Field-by-field Comparison
Field Before After
Text We cannot override {{c1::attributes inside a subclass}} they are {{c1::shadowed}}. We cannot override {{c1::attributes inside a subclass}}, they are {{c1::shadowed}}.
Extra class Animal { <br>&nbsp; String name = "Animal"; <br>&nbsp; String getName() { <br>&nbsp; &nbsp; return "Animal"; <br>&nbsp; } <br>} <br><br>class Dog extends Animal { <br>&nbsp; String name = "Dog"; <span style="font-style: italic;">// Shadows Animal.name (doesn't override it)</span> <br>&nbsp; @Override String getName() {&nbsp;return Dog";&nbsp;} <span style="font-style: italic;">// Overrides Animal.getName()</span> <br>}<br><br>Animal a = new Dog(); <br>System.out.println(a.name); <span style="font-style: italic;">// "Animal" — field access uses static type</span> <br>System.out.println(a.getName()); <span style="font-style: italic;">// "Dog" — method call uses dynamic type</span>
Tags: ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic

Note 2: ETH::1. Semester::EProg

Deck: ETH::1. Semester::EProg
Note Type: Horvath Cloze
GUID: iz]M]${2
modified

Before

Front

ETH::1._Semester::EProg::7._Classes_and_Objects::2._Enums
Enums have some convenience features:
  • can compare using ==
  • use .name() to get string representation
  • go from string to enum using Status.valueOf("PAID")
  • Ordering using order in declaration Status.SUBMITTED < Status.PAID

Back

ETH::1._Semester::EProg::7._Classes_and_Objects::2._Enums
Enums have some convenience features:
  • can compare using ==
  • use .name() to get string representation
  • go from string to enum using Status.valueOf("PAID")
  • Ordering using order in declaration Status.SUBMITTED < Status.PAID

After

Front

ETH::1._Semester::EProg::7._Classes_and_Objects::2._Enums
Enums have some convenient features:
  • can compare using ==
  • use .name() to get string representation
  • go from string to enum using Status.valueOf("PAID")
  • Ordering using order in declaration Status.SUBMITTED < Status.PAID

Back

ETH::1._Semester::EProg::7._Classes_and_Objects::2._Enums
Enums have some convenient features:
  • can compare using ==
  • use .name() to get string representation
  • go from string to enum using Status.valueOf("PAID")
  • Ordering using order in declaration Status.SUBMITTED < Status.PAID
Field-by-field Comparison
Field Before After
Text Enums have some convenience features:<br><ul><li>{{c1::can compare using <code>==}}</code></li> <li>{{c2::use <code>.name()</code> to get string representation}}</li> <li>{{c3::go from string to enum using <code>Status.valueOf("PAID")}}</code></li> <li>{{c4:: Ordering using order in declaration <code>Status.SUBMITTED &lt; Status.PAID</code>}}</li></ul> Enums have some convenient features:<br><ul><li>{{c1::can compare using <code>==::compare}}</code></li> <li>{{c2::use <code>.name()</code> to get string representation::string}}</li> <li>{{c3::go from string to enum using <code>Status.valueOf("PAID")::string conversion}}</code></li> <li>{{c4:: Ordering using order in declaration <code>Status.SUBMITTED &lt; Status.PAID::order</code>}}</li></ul>
Tags: ETH::1._Semester::EProg::7._Classes_and_Objects::2._Enums

Note 3: ETH::1. Semester::EProg

Deck: ETH::1. Semester::EProg
Note Type: Horvath Cloze
GUID: m5.*#}3,2{
modified

Before

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
Casting Compile Errors:
  • Cat c = new Cat(); Dog d = (Dog) c; Casting Static type Cat to Dog as they’re siblings.
  • Cat c = (Dog) d; Assigning static type of sibling or super-type to sub-type

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
Casting Compile Errors:
  • Cat c = new Cat(); Dog d = (Dog) c; Casting Static type Cat to Dog as they’re siblings.
  • Cat c = (Dog) d; Assigning static type of sibling or super-type to sub-type

After

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
Possible casting problems:
  • String s = (String) new Integer(5); Casting between unrelated classes
  • Animal a2 = new Cat(); Dog d2 = (Dog) a2; ClassCastException!

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
Possible casting problems:
  • String s = (String) new Integer(5); Casting between unrelated classes
  • Animal a2 = new Cat(); Dog d2 = (Dog) a2; ClassCastException!
Field-by-field Comparison
Field Before After
Text Casting Compile Errors:<br><ul><li>{{c1::<b>Cat c = new Cat(); Dog d = (Dog) c;</b> Casting Static type <b>Cat</b> to <b>Dog</b> as they’re siblings.}}</li><li>{{c2::<b>Cat c = (Dog) d;</b>&nbsp;Assigning static type of sibling or super-type to sub-type}}</li></ul> Possible casting problems:<br><ul><li>{{c1::String s = (String) new Integer(5); Casting between unrelated classes }}</li><li>{{c2::Animal a2 = new Cat(); Dog d2 = (Dog) a2; ClassCastException!}}</li></ul>
Tags: ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic

Note 4: ETH::1. Semester::EProg

Deck: ETH::1. Semester::EProg
Note Type: Horvath Cloze
GUID: oE~TL)}ZNN
modified

Before

Front

ETH::1._Semester::EProg::10._Inheritance
In java a class cannot inherit from multiple super-classes

Back

ETH::1._Semester::EProg::10._Inheritance
In java a class cannot inherit from multiple super-classes

This works only for interfaces.

After

Front

ETH::1._Semester::EProg::10._Inheritance
In Java a class cannot inherit from multiple super-classes.

Back

ETH::1._Semester::EProg::10._Inheritance
In Java a class cannot inherit from multiple super-classes.

This works only for interfaces.
Field-by-field Comparison
Field Before After
Text In java a class cannot inherit from {{c1:: multiple super-classes}} In Java a class cannot inherit from {{c1:: multiple super-classes}}.
Tags: ETH::1._Semester::EProg::10._Inheritance

Note 5: ETH::1. Semester::EProg

Deck: ETH::1. Semester::EProg
Note Type: Horvath Cloze
GUID: q+A$0CHp#W
modified

Before

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
If we override an attribute inherited from the subclass, it will override the parents attribute.

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
If we override an attribute inherited from the subclass, it will override the parents attribute.

class A {  
    public int x = 5;  

    public void fct1() {  
        System.out.println(this.x);  
    }  
}  

class B extends A {  
    public B() {  
        super.x = 10;  
    }  
    public B(int a) {  
        super.x = a;  
    }  
}

A a1 = new B(1);
A a2 = new B(12); // As these are different instances, their attributes are separate
B b1 = new B(1);
B b2 = new B(12);
a1.fct1(); // 1 -> Even though static type is A
a2.fct1(); // 12 -> Different output as a2's instance of A has 12
b1.fct1(); // 1 -> same here, even though it dynamic dispatches
b2.fct1(); // 12

After

Front

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
If we override an attribute inherited from the parentclass, it will override the parents attribute.

Back

ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
If we override an attribute inherited from the parentclass, it will override the parents attribute.

class A {
 public int x = 5;
 public void fct1() {
  System.out.println(this.x);
 }
}

class B extends A {
 public B() {
  super.x = 10;
 }
 public B(int a) {
  super.x = a;
 }
}

A a1 = new B(1);
A a2 = new B(12); // As these are different instances, their attributes are separate
B b1 = new B(1);
B b2 = new B(12);

a1.fct1(); // 1 -> Even though static type is A
a2.fct1(); // 12 -> Different output as a2's instance of A has 12
b1.fct1(); // 1 -> same here, even though it dynamic dispatches
b2.fct1(); // 12
Field-by-field Comparison
Field Before After
Text If we override an attribute inherited from the subclass, it will {{c1::override}} the parents attribute. If we override an attribute inherited from the parentclass, it will {{c1::override}} the parents attribute.
Extra <pre><code>class A { public int x = 5; public void fct1() { System.out.println(this.x); } } class B extends A { public B() { super.x = 10; } public B(int a) { super.x = a; } } A a1 = new B(1); A a2 = new B(12); // As these are different instances, their attributes are separate B b1 = new B(1); B b2 = new B(12); a1.fct1(); // 1 -&gt; Even though static type is A a2.fct1(); // 12 -&gt; Different output as a2's instance of A has 12 b1.fct1(); // 1 -&gt; same here, even though it dynamic dispatches b2.fct1(); // 12 </code></pre> <code>class A { <br>&nbsp;public int x = 5; <br>&nbsp;public void fct1() { <br>&nbsp; System.out.println(this.x); <br>&nbsp;} <br>} <br><br>class B extends A { <br>&nbsp;public B() { <br>&nbsp; super.x = 10; <br>&nbsp;} <br>&nbsp;public B(int a) { <br>&nbsp; super.x = a; <br>&nbsp;} <br>} <br><br>A a1 = new B(1); <br>A a2 = new B(12); // As these are different instances, their attributes are separate <br>B b1 = new B(1); <br>B b2 = new B(12); <br><br>a1.fct1(); // 1 -&gt; Even though static type is A <br>a2.fct1(); // 12 -&gt; Different output as a2's instance of A has 12 <br>b1.fct1(); // 1 -&gt; same here, even though it dynamic dispatches <br>b2.fct1(); // 12 </code>
Tags: ETH::1._Semester::EProg::10._Inheritance::2._Polymorphism::3._Static_vs_Dynamic
↑ Top