Multiple choice technology programming languages

class Root { int bark=10; public void get(){ System.out.println("Root"); } } public class Tree extends Root{ public void get(){ bark =15; System.out.println("Tree"); } public static void main(String[] args){ Tree t = new Tree(); Root r = new Root(); Root t1= new Tree(); r.get(); t.get(); t1.get(); System.out.println(t.bark); System.out.println(t1.bark); System.out.println(r.bark); } }

  1. Root Tree Tree 15 15 15

  2. Root Tree Tree 10 15 15

  3. Root Tree Root 15 15 10

  4. Root Tree Tree 15 15 10

  5. Root Tree Tree 15 10 10

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

Calling r.get() prints Root. Calling t.get() and t1.get() invokes the overridden get() method in Tree, printing Tree and setting bark to 15. Since bark is inherited from Root and not shadowed in Tree, t.bark and t1.bark both print 15, while r.bark remains 10 as it was never modified.