Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

AP CSA Question of the Day March 3, 2025

Reference
  1. Incorrect Correct No Answer was selected Invalid Answer

    The Animal, Cat, and Lion classes are defined as follows:

    public class Animal {
        private String name;
    
        public Animal(String name) {
            this.name = name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String toString() {
            return "I am a " + name;
        }
    }
    
    public class Cat extends Animal {
    
        public Cat() {
            super("Cat");
        }
    
        public String speak() {
            return "meow!";
        }
    
        @Override
        public String toString() {
            return super.toString() + ", " + speak();
        }
    }
    
    public class Lion extends Cat {
    
        public Lion() {
            super();
            this.setName("Lion");
        }
    
        @Override
        public String speak() {
            return "rawr!";
        }
    }
    Java

    What will the following program output?

    Lion lion = new Lion();
    System.out.println(lion.toString());
    Java