Question
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
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
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.