I got the following code on 4test web site. Which print out is right? ************** Given the following classes defined in separate files: class Vehicle { public void drive() { System.out.println("Vehicle: drive"); } } class Car extends Vehicle { public void drive() { System.out.println("Car: drive"); } } public class Test { public static void main (String args []) { Vehicle v; Car c; v = new Vehicle(); c = new Car(); v.drive(); c.drive(); v = c; v.drive(); } }
Prints out: Vehicle : drive Car : drive Car : drive or Prints out: Vehicle : drive Car : drive Vehicle : drive ******************************* Thanks!
John Lee
Ranch Hand
Joined: Aug 05, 2001
Posts: 2545
posted
0
I think it is: Vehicle : drive Car : drive Car : drive
kishor rao
Ranch Hand
Joined: Dec 10, 2002
Posts: 35
posted
0
i agree with don. thats the output because of the default polymorphic feature of java
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
Mhh, why didn't you just try it?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.