# Fun with Polymorphism in Java!

🚀 Just coded a funny example of polymorphism in Java! 🎉 Meet my zoo😂😂:

🐺 Wolf: "I howl at the moon and scare the villagers!"

🐱 Cat: "I meow for attention and secretly judge you."

🐮 Cow: "I moo peacefully while chewing cud all day."

🦆 Duck: "I quack loudly just because I can!"

Check out the magic of polymorphism script! 👇

**#Java** **#Coding** **#Polymorphism** **#ProgrammingFun**

package MondayPractice;

abstract class Janwar {

abstract void sound(); // Abstract method to be implemented by subclasses

}

class Wolf extends Janwar {

void sound() { // Implementing abstract method

System.out.println("Wolf says: 🐺 'I howl at the moon and scare the villagers!'");

}}

class Cat extends Janwar {

void sound() { // Implementing abstract method

System.out.println("Cat says: 🐱 'I meow for attention and secretly judge you.'");

}}

class Cow extends Janwar {

void sound() {

System.out.println("Cow says: 🐮 'I moo peacefully while chewing cud all day.'");

}}

class Duck extends Janwar {

void sound() {

System.out.println("Duck says: 🦆 'I quack loudly just because I can!'");

}}

// Polymorphism allows methods to do different things based on the object it is acting upon.

public class PolymorphismAdvanced {

public static void main(String\[\] args) {

// Array of Janwar references

Janwar\[\] zoo = {new Wolf(), new Cat(), new Cow(), new Duck()};

System.out.println("Welcome to the Funny Zoo! 🎉");

System.out.println("Let's hear some animal sounds...");

// Loop through each animal in the zoo and call their sound method

for (Janwar animal : zoo)

animal.sound();

}}
