calculate the kilometer within an hour class car


Calculate the kilometer within an hour?

class Car {

String licensePlate = ""; // e.g. "New York 543 A23"
double speed = 0.0; // in kilometers per hour
double maxSpeed = 123.45; // in kilometers per hour
void floorIt() {
speed = maxSpeed;
}

}
Within the Car class, you don't absolutely required to prefix the field names along with this. like this.licensePlate or this.speed. Just licensePlate and speed are enough. The this. may be implied. That's because the floorIt() method must be called through a specific instance of the Car class, and this instance knows what its data is. Or, another way of looking at it, the every object has its own floorIt() method.

For clarity, I will use an explicit this today, and I recommend you do so too, at least initially. As you become more comfortable along with Java, classes, references, and OOP, you will be able to leave out the this without fear of confusion. Many real-world code does not use an explicit this.

 

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: calculate the kilometer within an hour class car
Reference No:- TGS0284521

Expected delivery within 24 Hours