Online Course Discussion Forum

APCSA question

 
 
Picture of Dr. Kevin Wang
Re: APCSA question
by Dr. Kevin Wang - Monday, 13 March 2023, 5:04 PM
 

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.