Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

// Interface defining behaviors interface Animal { void makeSound(); // Abstract method }

// Abstract class providing base properties and methods abstract class Mammal implements Animal { String name;

// Constructor
public Mammal(String name) {
    this.name = name;
}

// Concrete method
void sleep() {
    System.out.println(name + " is sleeping...");
}

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

}

// Concrete class implementing the abstract class class Dog extends Mammal {

// Constructor
public Dog(String name) {
    super(name);
}

// Implementing abstract method
@Override
void move() {
    System.out.println(name + " is running...");
}

// Implementing interface method
@Override
public void makeSound() {
    System.out.println(name + " says: Woof Woof!");
}

}

// Main class to test the implementation public class AnimalTest { public static void main(String[] args) { Dog myDog = new Dog("Buddy"); // Creating a Dog object myDog.makeSound(); // Calling interface method myDog.move(); // Calling abstract class method implementation myDog.sleep(); // Calling concrete method from abstract class } }

About

lab one repository

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors