I'm fairly new to Java. I do have a background in C++ but I seem to be having some trouble with Java. My biggest problem is that I seem to be mixing up Java and C++ and things are getting a little confusing.
I have one of my trusty C++ books with me along with some fangled Java book. I need to catch up with Java or else I will end up stalling our little team project.
I found a simple example in the C++ book and thought it would be a good idea to translate it to Java. This should have been simple,but I'm getting tons of errors and problems. Any help would be grealy appreciated.
My problem:
Create a class Vehicle which has 2 data max_speed and max_Weight. Include a method display() which does nothing.
Create a class Car that extends Vehicle . It has another data field Model and has a contructor Car() that initialises all the three fields to typical values. Override the display() method to print to the console as follows:
MODEL : XXXXX RATIO : max_weight/max_speed(to be computed)
Finally,create an independent class Car_Info containing the main(String []) function which instantiates the Car class and calls its display() method.
Do I need to put the class files in two seperate files even though one is inherited?
My initial ongoing weak attempt. (for your humor if nothing else)
I have one of my trusty C++ books with me along with some fangled Java book. I need to catch up with Java or else I will end up stalling our little team project.
I found a simple example in the C++ book and thought it would be a good idea to translate it to Java. This should have been simple,but I'm getting tons of errors and problems. Any help would be grealy appreciated.
My problem:
Create a class Vehicle which has 2 data max_speed and max_Weight. Include a method display() which does nothing.
Create a class Car that extends Vehicle . It has another data field Model and has a contructor Car() that initialises all the three fields to typical values. Override the display() method to print to the console as follows:
MODEL : XXXXX RATIO : max_weight/max_speed(to be computed)
Finally,create an independent class Car_Info containing the main(String []) function which instantiates the Car class and calls its display() method.
Do I need to put the class files in two seperate files even though one is inherited?
My initial ongoing weak attempt. (for your humor if nothing else)
code:<HR>Code:class Vehicle { int max_speed; int max_weight; public Vehicle(int x,int y) { max_speed = x; max_weight = y; } public void display() { } }<P> class Car extends Vehicle { public Car(int z) { model = z; model = 490; max_speed = 55; max_weight = 2000; ratio = max_weight/max_speed; } public void display() { System.out.println("MODEL" + model + "RATIO" + ratio); } }