Multiple choice technology programming languages

  1. public class Tenor extends Singer { 4. public static String sing() { return "fa"; } 5. public static void main(String[] args) { 6. Tenor t = new Tenor(); 7. Singer s = new Tenor(); 8. System.out.println(t.sing() + " " + s.sing()); 9. } 10. } 11. class Singer { public static String sing() { return "la"; } }

  1. fa fa

  2. fa la

  3. la la

  4. Compilation fails

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

Static methods in Java are bound at compile-time based on the reference type, not the actual object type. The variable t has type Tenor, so t.sing() calls Tenor.sing() returning 'fa'. The variable s has type Singer, so s.sing() calls Singer.sing() returning 'la', despite s referencing a Tenor object.