我现在边工作,业余时间看看,更新的可能的比较慢,望大家谅解。
题58
Given the code fragment: |
if(aVar++ < 10){ System.out.println(aVar+ " Hello World!"); }else{ System.out.println(aVar+" Hello Universe!"); } |
What is the result if the integer aVar is 9? |
------------------------------------------------------------- |
Answer: A |
解析:1. if(aVar++ < 10) : aVar是先判断后自增,此时aVar是9。 2. System.out.println(aVar+ " Hello World!"): aVar已经自增过了,所以是10 |
题59
Given: |
class X { public void mX() { System.out.println("Xm1"); } }
class Y extends X{ public void mX() { System.out.println("Xm2"); } public void mY() { System.out.println("Ym"); } }
public class Test{ public static void main(String[] args) { X xRef = new Y(); Y yRef=(Y)xRef; yRef.mY(); xRef.mX(); } } |
A. Ym |
------------------------------------------------------------- |
Answer: B |
解析:1. 由于Y yRef=(Y)xRef;把父类强转为子类了。所以yRef.mY();没有问题。排除选项C和选项D。 2. xRef.mX(); 多态情况下,子父类存在同名的非静态的成员函数时,访问的是子类的成员函数。1z0-808.236q.pdf文档有误。这题正确的选项是A。 |