classes and methods help......
i am learning about classes. i have written program named Vehicle.java as follows :
import java.io.*;
public class Vehicle {
// Attributes
private Stringmake;
private Stringmodel;
private intyearOfManufacture;
public floatspeed;
// Constructors
public Vehicle(String make, String model, int year, float speed) {
this.make = make;
this.model = model;
this.yearOfManufacture = year;
this.speed=speed;
}
// Get / Set methods for the attributes
// Get / Set for Make
public String getMake()
{
return (this.make);
}
public void setMake(String newMake)
{
this.make = newMake;
}
// Same for model and year of manufacture
public float getSpeed()
{
return (this.speed);
}
// Methods
public void accelerate()
{
// increases the speed
this.speed++;
}
public void decelerate()
{
// decreases the speed
this.speed--;
}
public void stop()
{
// come to a stop
this.speed = 0;
}
public boolean isMoving()
{
if (speed == 0)
return (false);
else
return (true);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
and another program called Car.java as follows :
import java.io.*;
public class Car extends Vehicle {
public void accelerate()
{
// The same method in Vehicle class incremented speed
speed = speed + 5;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
when i compiled Vehicle.java, it didnt show any error. but when i tried to compile Car.java, the follwowing error was there:
import java.io.*;
public class Car extends Vehicle {
public void accelerate()
{
// The same method in Vehicle class incremented speed
speed = speed + 5;
}
}
why that error?
can anyone hlp me, please.......

