using Abstraction;

namespace Abstraction
{

// Abstract class
abstract class Animal
{
// Abstract method (does not have a body)
public abstract void animalSound();
// Regular method
public void sleep()
{
System.out.println("Zzz");
}
}

// Subclass (inherit from Animal)

class Pig extends Animal
{
public void animalSound()
{
System.Out.println("The pig says: wee wee");

}
}

class Main
{
public static void main(String[] args)
{
Pig myPig = new Pig(); // Create a Pig object
myPig.animalSound();
myPig.sleep();
}
}

}

Explain this abstraction code

This code demonstrates the concept of abstraction in object-oriented programming.

In this code, the abstract class `Animal` is defined with an abstract method `animalSound()` and a regular method `sleep()`. The abstract method `animalSound()` does not have a body and is intended to be implemented in subclasses. The regular method `sleep()` has a body and can be used as is in subclasses.

The subclass `Pig` extends the `Animal` class and provides an implementation for the `animalSound()` method by printing "The pig says: wee wee".

In the `Main` class, an object of the `Pig` class is created, and the `animalSound()` and `sleep()` methods are called on this object. This demonstrates how abstraction allows us to define a common interface in the abstract class while leaving the specific implementation to the subclasses.

Overall, abstraction allows for creating a hierarchy of classes with common methods and properties defined in an abstract class, while leaving implementation details to the concrete subclasses. It helps in achieving modularity, reusability, and code organization in object-oriented programming.