From 6685023b72ff22870b26b687047e34272b3221cc Mon Sep 17 00:00:00 2001 From: Juuso Rytilahti <juuso.b.rytilahti@utu.fi> Date: Thu, 30 May 2024 13:26:34 +0000 Subject: [PATCH] Added exercise 3 --- Exercise3/Exercise3.java | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Exercise3/Exercise3.java diff --git a/Exercise3/Exercise3.java b/Exercise3/Exercise3.java new file mode 100644 index 0000000..eafdc30 --- /dev/null +++ b/Exercise3/Exercise3.java @@ -0,0 +1,50 @@ +package fi.utu.tech.ooj.exercise4.exercise3; + +interface Winged { + default void fly() { + System.out.println(this + " flies!"); + } +} + +interface Bipedal { + default void walk() { + System.out.println(this + " walks!"); + } +} + +abstract class Bird implements Winged, Bipedal { + +} + +class Crow extends Bird { + private static int idx = 0; + private int id = ++idx; + + @Override + public String toString() { + return "Varis " + id; + } +} + +public class Teht3 { + public Teht3() { + System.out.println("Exercise 3"); + + challenge1(new Crow()); + challenge2(new Crow()); + } + + void challenge1(Bird b) { + System.out.println("In this challenge, we fly and then we walk!"); + + b.fly(); + b.walk(); + } + + <X extends Winged & Bipedal> void challenge2(X b) { + System.out.println("In this challenge, we fly and then we walk!"); + + b.fly(); + b.walk(); + } +} -- GitLab