Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sample Questions for Computer Science A 15. Consider the following two classes.

ID: 3829048 • Letter: S

Question

Sample Questions for Computer Science A 15. Consider the following two classes. public class Dog public void act System.out. print ("run eat. public void eat. System.out.print eat public class Under Dog extends Dog public void act super act System.out.print sleep public void eat super eat. System.out.print bark Assume that the following declaration appears in a class other than Dog. Dog fido new U Dog nder What is printed as a result of the call fido. act (B) run eat sleep (c) run eat sleep bark (D) run eat bark sleep (E) Nothing is printed due to infinite recursion. o 2014 The College Board. Visit the College Board on the Web www.college board org

Explanation / Answer


/*
output:

run eat bark sleep
*/

fido object of Dog class is creatd with reference to UnderDog class
during run time.

Hence act method of Underdog is called.
act method of Underdog calls super act method of Parent class
which is Dog class
followed by eat method of dog class.

the program flow comes back to the eat method of Underdog
and print bark is executed

with the flow coming back to act method of Underdog
and finally print sleep is executed

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote