0% found this document useful (0 votes)
4 views2 pages

Java Abstract Class Animal Example

Uploaded by

Juan Dela Cruz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Java Abstract Class Animal Example

Uploaded by

Juan Dela Cruz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Animal.

java

public abstract class Animal {

// Abstract method (no implementation)

abstract void makeSound();

// Concrete method

void sleep() {

[Link]("Zzzz...");

[Link]

public class Dog extends Animal {

@Override

void makeSound() {

[Link]("Woof! Woof!");

[Link]

public class Cat extends Animal {

@Override

void makeSound() {

[Link]("Meow!");

=====================================================================================
[Link] – Main

public class AbstractExample {

public static void main(String[] args) {

Dog myDog = new Dog();

Cat myCat = new Cat();

// Invoking methods

[Link]();

[Link]();

[Link]();

[Link]();

Output

You might also like