6.10. Sample exam questions

Q6-1.

What is the output of the following code?

class Animal {
    void jump() { System.out.println("Animal"); }
}
class Cat extends Animal {
    void jump(int a) { System.out.println("Cat"); }
}
class Rabbit extends Animal {
    void jump() { System.out.println("Rabbit"); }
}
class Circus {
    public static void main(String args[]) {
        Animal cat = new Cat();
        Rabbit rabbit = new Rabbit();
        cat.jump();

        rabbit.jump();
    }
}
  1. Animal
    Rabbit
  2. Cat
    Rabbit
  3. Animal
    Animal
  4. None of the above

Q6-2.

Given the following code, select the correct statements:

class Flower { public void fragrance() {System.out.println("Flower"); } } class Rose { public void fragrance() {System.out.println("Rose"); } } class Lily { public void fragrance() ...

Get OCA Java SE 8 Programmer I Certification Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.