Multiple choice technology programming languages

What is the result of compiling and running this program? class Clove{ void quality(Clove m){ System.out.println("Clove is nice"); } } class Mint extends Clove{ void quality(Mint c){ System.out.println("Mint is ok"); } } class Sage extends Mint{ void quality(Sage h){ System.out.println("Sage is average"); } } public class Test{ public static void main(String[] args){ Clove h = new Sage(); Mint c = new Sage(); c.quality(h); } }

  1. prints "Clove is nice"

  2. prints "Mint is ok"

  3. prints "Sage is average"

  4. Class cast Exception at runtime.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The variable c is declared as type Mint. The method c.quality(h) calls quality() on a Mint reference. The argument h is declared as Clove, so the method signature quality(Mint c) in class Mint doesn't match. JVM looks for quality(Clove) in Mint's hierarchy, finds it in Clove class (parent), and executes that due to method resolution rules.