| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
hard
Static Methods and Inheritance
< Prev
Next >

Consider the following class declarations.

public class Animal {
    public static void makeSound() {
        System.out.println("Some generic animal sound");
    }
}

public class Dog extends Animal {
    public static void makeSound() {
        System.out.println("Bark");
    }
}

The following code segment is executed in a method of a class other than Animal or Dog.

Animal animal = new Dog();
animal.makeSound();

What is the output when the code segment is executed?

A

Some generic animal sound

B

Some generic animal sound
Bark

C

Bark

D

Nothing is printed because the code does not compile.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy