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

Inheritance in Object-Oriented Programming

Question 1
Computer Science AAPConcept Practice
1 mark

Which of the following statements best describes the relationship between a superclass and a subclass?

Question 2
Computer Science AAPConcept Practice
1 mark

Given the following code snippet, which class is the superclass?

Question 3
Computer Science AAPConcept Practice
1 mark

Which of the following statements is true regarding the accessibility of superclass members by a subclass?

Question 4
Computer Science AAPConcept Practice
1 mark

What is the correct syntax to create a subclass 'Car' that inherits from a superclass 'Vehicle'?

Question 5
Computer Science AAPConcept Practice
1 mark

If a class does not explicitly extend another class in Java, what class does it implicitly extend?

Question 6
Computer Science AAPConcept Practice
1 mark

What is the primary purpose of the super() keyword in a subclass constructor?

Question 7
Computer Science AAPConcept Practice
1 mark

Consider the following code:

java
class Animal {
    public Animal(String name) {
        System.out.println("Animal constructor: " + name);
    }
}

class Dog extends Animal {
    public Dog(String name) {
        super(name);
    }
}

public class Main {
    public static void main(String[] args) {
        Dog my...
Feedback stars icon

How are we doing?

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

Question 8
Computer Science AAPConcept Practice
1 mark

In a multi-level inheritance hierarchy (e.g., ClassA extends ClassB extends ClassC), where should super() be called to initialize variables defined in ClassC when constructing an object of ClassA?

Question 9
Computer Science AAPConcept Practice
1 mark

When would you use super.method() in a subclass?

Question 10
Computer Science AAPConcept Practice
1 mark

Consider the following code:

java
class Vehicle {
    int speed = 0;

    public void accelerate() {
        speed += 10;
    }

    public int getSpeed() {
        return speed;
    }
}

class Car extends Vehicle {
    public void accelerate() {
        super.accelerate();
        speed += 20;
    }
}

public clas...