Question: Consider the following two classes. A 2 5 - line code segment reads as follows. Line 1 : public class Dog. Line 2 : open

Consider the following two classes.
A 25-line code segment reads as follows. Line 1: public class Dog. Line 2: open brace. Line 3: public void act, open parenthesis, close parenthesis. Line 4: open brace. Line 5: System, dot, out, dot, print, open parenthesis, open double quote, run, space, close double quote, close parenthesis, semicolon. Line 6: eat, open parenthesis, close parenthesis, semicolon. Line 7: close brace. Line 8: public void eat, open parenthesis, close parenthesis. Line 9: open brace. Line 10: System, dot, out, dot, print, open parenthesis, open double quote, eat, space, close double quote, close parenthesis, semicolon. Line 11: close brace. Line 12: close brace. Line 13: public class Under Dog extends Dog. Line 14: open brace. Line 15: public void act, open parenthesis, close parenthesis. Line 16: open brace. Line 17: super, dot, act, open parenthesis, close parenthesis, semicolon. Line 18: System, dot, out, dot, print, open parenthesis, open double quote, sleep, space, close double quote, close parenthesis, semicolon. Line 19: close brace. Line 20: public void eat, open parenthesis, close parenthesis. Line 21: open brace. Line 22: super, dot, eat, open parenthesis, close parenthesis, semicolon. Line 23: System, dot, out, dot, print, open parenthesis, open double quote, bark, space, close double quote, close parenthesis, semicolon. Line 24: close brace. Line 25: close brace.
Assume that the following declaration appears in a class other than Dog.
Dog fido = new UnderDog () ;
What is printed as a result of the call fido.act()?
Responses
run eat
run eat
run eat sleep
run eat sleep
run eat sleep bark
run eat sleep bark
run eat bark sleep
run eat bark sleep
Nothing is printed due to infinite recursion.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!