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

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

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

Question 4
college-boardComputer Science AAPExam Style
1 mark

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

Question 5
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 6
college-boardComputer Science AAPExam Style
1 mark

Suppose there is a Car class that extends the Vehicle class and whose constructor takes in the “brand” and “year” parameters. What is the static type and dynamic type of the variable "lambo" in the following code?

Car lambo = new Car(“Lamborghini”, 2005);
Question 7
college-boardComputer Science AAPExam Style
1 mark

In a class hierarchy where Class B extends Class A, and Class C extends Class B, which method would be invoked if a method in Class A is overridden by both Classes B and C and an object of type C calls the method?

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

In Java, what indicates that polymorphism has been used effectively in code design?

Question 9
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?

Question 10
college-boardComputer Science AAPExam Style
1 mark

What is the purpose of polymorphism in object-oriented programming?