Online Course Discussion Forum

APCSA question

 
 
WangDr. Kevin的头像
Re: APCSA question
WangDr. Kevin - 2023年03月13日 Monday 17:04
 

Does it compile at all?  The "food" variable is of "Food" class.  Even though the object it references is a "Pizza" type, the compiler would not know that, so it should not know the "s2" field is available. I would expect the compiler to give an error right there. I am surprised that the code could pass compile and start to run.