Describe the superclass in inheritance, JAVA Programming

Assignment Help:

Describe the Superclass in Inheritance ?

In this example you start through defining a more common MotorVehicle class.
public class MotorVehicle {

private String licensePlate; // e.g. "New York A456 324"
private double speed; // kilometers per hour
private double maxSpeed; // kilometers per hour
private String make; // e.g. "Harley-Davidson", "Ford"
private String model; // e.g. "Fatboy", "Taurus"
private int year; // e.g. 1998, 1999, 2000, 2001, etc.
private int numberPassengers; // e.g. 4

// constructors
public MotorVehicle(String licensePlate, double maxSpeed,
String make, String model, int year, int numberOfPassengers) {
this(licensePlate, 0.0, maxSpeed, make, model, year, numberOfPassengers);
}

public MotorVehicle(String licensePlate, double speed, double maxSpeed,
String make, String model, int year, int numberOfPassengers) {

// I could add some more constraints like the
// number of doors being positive but I won't
// so that this example doesn't get too big.
this.licensePlate = licensePlate;
this.make = make;
this.model = model;
this.year = year;
this.numberPassengers = numberOfPassengers;

if (maxSpeed >= 0.0) {
this.maxSpeed = maxSpeed;
}
else {
maxSpeed = 0.0;
}

if (speed < 0.0) {
speed = 0.0;
}

if (speed <= maxSpeed) {
this.speed = speed;
}
else {
this.speed = maxSpeed;
}

}


// getter (accessor) methods
public String getLicensePlate() {
return this.licensePlate;
}

public String getMake() {
return this.make;
}

public String getModel() {
return this.model;
}

public int getYear() {
return this.year;
}

public int getNumberOfPassengers() {
return this.numberPassengers;
}

public int getNumberOfPassengers() {
return this.numberWheels;
}

public double getMaxSpeed() {
return this.maxSpeed;
}

public double getSpeed() {
return this.speed;
}

// setter method for the license plate property
protected void setLicensePlate(String licensePlate) {
this.licensePlate = licensePlate;
}

// accelerate to maximum speed
// put the pedal to the metal
public void floorIt() {
this.speed = this.maxSpeed;
}

public void accelerate(double deltaV) {

this.speed = this.speed + deltaV;
if (this.speed > this.maxSpeed) {
this.speed = this.maxSpeed;
}
if (this.speed < 0.0) {
this.speed = 0.0;
}
}
}
The MotorVehicle class has all the features shared through motorcycles and cars, but it leaves the number of wheels unspecified, and it doesn't have a numberDoors field since not all motor vehicles have doors. It also forms the fields and the setLicensePlate() method protected on the other hands of private and public. 


Related Discussions:- Describe the superclass in inheritance

What is arpanet and who developed it, What is ARPANET and who developed it?...

What is ARPANET and who developed it? ARPANET stands for Advanced Research Projects. The initial reasons were to communicate along with and share computer resources between mainl

What system.out.println() signifies, What 'System.out.println()' signifies?...

What 'System.out.println()' signifies? 'System' is a predefined class. System class gives access to the system. 'out' is the output stream. 'println' is printin

Jsp retrive data, how to retrive data in one block from database by click ...

how to retrive data in one block from database by click data link in another block

Integration of neo4j and opengeo, Integration: Neo4J, OpenGeo, Ikanow Pr...

Integration: Neo4J, OpenGeo, Ikanow Project Description: I have an ongoing project to loosely integrate a variety of existing Open Source products: OpenGeo (geospatial server

Rmi-iiop support dynamic downloading of classes, Does RMI-IIOP support dyna...

Does RMI-IIOP support dynamic downloading of classes? Ans) No, RMI-IIOP doesn't support dynamic downloading of the classes as it is complete with CORBA in DII (Dynamic Interface

Java developer with spring framework needed, Java developer with spring fra...

Java developer with spring framework needed I need an experienced person in java with spring frame work. Desired Skills are Java

What is includeaction, The IncludeAction class is useful when you require t...

The IncludeAction class is useful when you require to integrate Struts into an application that uses Servlets. Use the IncludeAction class to contain another resource in the respon

I want customize tumblr theme, I need Customize Tumblr theme Project Des...

I need Customize Tumblr theme Project Description: I have a blog here I would like to customize it as follows; 1) Modify the horizontal navigation from the bottom of th

Relational mapping integration module, What are object/relational mapping i...

What are object/relational mapping integration module? Ans) Spring also supports for using of an object/relational mapping (ORM) tool over straight JDBC by giving the ORM module

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd