diff --git a/OOP/Java/Lab/Week6/Bike/Biker.java b/OOP/Java/Lab/Week6/Bike/Biker.java new file mode 100644 index 0000000..b41b0ba --- /dev/null +++ b/OOP/Java/Lab/Week6/Bike/Biker.java @@ -0,0 +1,43 @@ +class Bike { + + int speedlimit = 80; + + void run() { + System.out.println("Bike speed limit: " + speedlimit + " km/h"); + } +} + +class Splendar extends Bike { + + int speedlimit = 60; + + void run() { + System.out.println("Splendar speed limit: " + speedlimit + " km/h"); + } +} + +class Biker { + + public static void main(String[] args) { + // Create objects for runtime polymorphism + Bike bike = new Bike(); + Bike splendar = new Splendar(); + + // Demonstrate runtime polymorphism through method calls + bike.run(); + splendar.run(); + + // Check whether runtime polymorphism can be achieved through data members + System.out.println("Bike speedlimit: " + bike.speedlimit); + System.out.println("Splendar speedlimit: " + splendar.speedlimit); + if (bike.speedlimit == splendar.speedlimit) { + System.out.println( + "Runtime polymorphism is not achieved through data members." + ); + } else { + System.out.println( + "Runtime polymorphism is achieved through data members." + ); + } + } +}