What is the result?

Given:
11. class Automobile {
12. public void drive() { System.out.print(“go forward “); }
13. }
14. class Ferrari extends Automobile {
15. public void drive () { System.out.print(“go fast “); }
16. }
17. public class Driver {
18. public static void main(String[] args) {
19. Automobile[] autos = { new Automobile(), new Ferrari() };
20. for (int x = 0; x < autos.length; x++)
21. autos[x].drive();
22. }
23. }

What is the result?

Given:
11. class Automobile {
12. public void drive() { System.out.print(“go forward “); }
13. }
14. class Ferrari extends Automobile {
15. public void drive () { System.out.print(“go fast “); }
16. }
17. public class Driver {
18. public static void main(String[] args) {
19. Automobile[] autos = { new Automobile(), new Ferrari() };
20. for (int x = 0; x < autos.length; x++)
21. autos[x].drive();
22. }
23. }

What is the result?

A.
go forward go forward

B.
Compilation fails due to an error on line 19.

C.
Compilation fails due to an error on line 15.

D.
go fast go forward

E.
go fast go fast

F.
go forward go fast

G.
Compilation fails due to an error on line 21.



Leave a Reply 0

Your email address will not be published. Required fields are marked *