0% found this document useful (0 votes)
4 views

4 oo[

2

Uploaded by

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

4 oo[

2

Uploaded by

za314944
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment No 4

abstract class Animal {

public abstract void makeSound();

public void eat() {

System.out.println("This animal is eating.");

class Dog extends Animal {

@Override

public void makeSound() {

System.out.println("The dog barks.");

class Cat extends Animal {

@Override
public void makeSound() {

System.out.println("The cat meows.");

public class Main2 {

public static void main(String[] args) {

Animal[] animals = new Animal[2];

animals[0] = new Dog();

animals[1] = new Cat();

for (Animal animal : animals) {

animal.makeSound();

animal.eat();

System.out.println();

}
}

You might also like