题目
题目

2025FA CSC-239-01H Assessment 1

简答题

For the following code (Same as Method dispatch 1), assume that: Classes Person, Animal, Dog, and Cat are all defined. Dog and Cat are subclasses of Animal. Animal, Dog, and Cat all implement a sayHello method Person implements a greet method Look at line 10. The first time through the loop, what class does Java use for a, to choose which sayHello() method to run?

题目图片
查看解析

查看解析

标准答案
Please login to view
思路分析
The question asks about which class Java uses for the variable a when evaluating a.sayHello() on the first loop iteration. First, examine the loop structure: for (Animal a : this.pets) { this.occupant.greet(a); a.sayHello(); } - The loop declares a as a reference to Animal......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

类似问题

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!