zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcardStudy GuideStudy GuideQuestion BankQuestion Bank
GlossaryGlossary

Inheritance in Object-Oriented Programming

Question 1
college-boardComputer Science AAPExam Style
1 mark

Given the following code:

class A {
    public void show() {
        System.out.println("A");
    }
}

class B extends A {
    public void show() {
        System.out.println("B");
    }
}

What will be the output when the following code is executed?

A obj1 = new A();
B obj2 = new B();
A obj3 = new B();

...
Question 2
college-boardComputer Science AAPExam Style
1 mark

Assume the following code is valid. What is the static type and dynamic type of the variable "ref"?

G ref = new H();
Question 3
college-boardComputer Science AAPExam Style
1 mark

In Java, can a subclass object be assigned to a superclass reference variable?

Question 4
college-boardComputer Science AAPExam Style
1 mark

What is the ability of different classes to respond to the same method call known as?

Question 5
college-boardComputer Science AAPExam Style
1 mark

Which statement is true when a superclass reference refers to a subclass object in Java?

Question 6
college-boardComputer Science AAPExam Style
1 mark

If an abstract class Shape has a non-abstract method draw(), and Circle is a subclass that does not override draw(), what happens when (Shape)new Circle().draw() is executed?

Question 7
college-boardComputer Science AAPExam Style
1 mark

In a game where Player is an abstract class and Archer and Knight are subclasses, which approach best utilizes polymorphism when implementing attack behaviors specific to archers and knights?

Feedback stars icon

How are we doing?

Give us your feedback and let us know how we can improve

Question 8
college-boardComputer Science AAPExam Style
1 mark

Given an array list 'animals' containing instances of various classes such as Dog, Cat, and Bird that all extend Animal and override speak(), what will be the Big O time complexity when sequentially calling speak() on each element?

Question 9
college-boardComputer Science AAPExam Style
1 mark

In Java, why would you choose composition over inheritance when designing long-term evolutionary software systems?

Question 10
college-boardComputer Science AAPExam Style
1 mark

Given a superclass Animal and subclasses Dog and Cat that override a makeSound() method, which line of code demonstrates polymorphism?