题目
题目

CS_2114_Spring2025 01.00 CS 2114 Readiness questions (classic)

单项选择题

Suppose the Dog and Animal classes are imported and both have run and eat methods defined with no parameters.  Given the following code: 11 Dog fido; 12 Animal simba = new Animal(); 13 simba.run(); 14 fido.eat(); 15 fido.run(); Which line will cause an error?

选项
A.none of these lines of code will cause an error
B.I don't know
C.14
D.15
E.13
F.12
查看解析

查看解析

标准答案
Please login to view
思路分析
Begin by noting what the code is doing line by line and what the declarations imply. Option analysis: Option 1: 'none of these lines of code will cause an error' — This would be true only if every statement could execute without a problem. However, the line 11 declares a local variable fido of type Dog but does not initialize it. In many languages like Java, using an uninitialized local variable to call a method (as done in lines 14 and 15) is not allowed. So this blanket statem......Login to view full explanation

登录即可查看完整答案

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

更多留学生实用工具

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