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.......

[2243 byte] By [lakshmi_narayanan_sa] at [2007-11-26 20:19:30]
# 1

> why that error?

What error? You didn't show the compiler's error diagnostic message.

I bet it was complaining about the 'Vehicle' identifier, i.e. it couldn't find

it. Although the Vehicle.class might be present in your current working

directory, the compiler won't look there by default. It just looks in those

directories which are part of your classpath. You can set this classpath

on the command line of the javac command:

javac -classpath . Car.java

note the dot '.' it represents the current working directory where your

Vehicle.class file is stored.

kind regards,

Jos

JosAHa at 2007-7-10 0:43:31 > top of Java-index,Java Essentials,Java Programming...