?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Polymorphic Method Calls

APCSA-OVVP1K

Consider the following classes.

public class Language { 
    // instance variables and constructor not shown 

    public void sayHello() { 
        System.out.println(“Hello”); 
    }

    public void sayGoodbye() { 
        System.out.println(“Good bye”); 
    }
}
public class FrenchLanguage extends Language {
    // instance variables and constructor not shown

    public void sayHello() { 
        System.out.println(“Bonjour”); 
    }
}
public class GermanLanguage extends Language { 
    // instance variables and constructor not shown 

    public void sayHello() { 
        System.out.println(“Guten Tag”); 
    } 
    public void sayGoodbye() { 
        System.out.println(“Auf Wiedersehen”); 
    }
}

Which of these sections of code contain polymorphic method calls?
I.

Language lang = new Language();
lang.sayGoodbye();
lang = new FrenchLanguage();
lang.sayGoodbye();

II.


Language lang = new Language();
lang.sayHello();
lang = new FrenchLanguage();
lang.sayHello();

III.


Language lang = new Language();
lang.sayGoodbye();
lang = new GermanLanguage();
lang.sayGoodbye();
A

III only.

B

I and II only.

C

I and III only.

D

II and III only.

E

I, II, and III.