Create a program using constructors, JAVA Programming

Assignment Help:

Create a program Using Constructors?

The further program uses the constructor to initialize a car rather than setting the areas directly.
class CarTest7 {

public static void main(String args[]) {

Car c = new Car("New York A45 636", 123.45);

System.out.println(c.getLicensePlate() + " is moving at " + c.getSpeed() +
" kilometers per hour.");

for (int i = 0; i < 15; i++) {
c.accelerate(10.0);
System.out.println(c.getLicensePlate() + " is moving at " + c.getSpeed()
+ " kilometers per hour.");
}

}
}
You no longer required knowing about the fields licensePlate, speed and maxSpeed. All you required to know is how to construct a new car and how to print it.

You might ask whether the setLicensePlate() method is still required since it's now set in a constructor. The common answer to this question depends on the use to that the Car class is to be put. The exact question is whether a car's license plate may required to be changed after the Car object is formed.

A few classes may not change after they're created; or, if they do change, they'll represent a different object. The most general such class is String. You cannot change a string's data. You can only form a new String object. Such objects are known as immutable.


Related Discussions:- Create a program using constructors

Explain what is object in java language, Explain what is Object in JAVA lan...

Explain what is Object in JAVA language? They are foundation of object oriented language. They are data structure holds data fields and properties and methods

What are the services given by the rmi object, RMI Object services: In...

RMI Object services: In addition to its remote object architecture, RMI gives some basic object services, which may be needed in a distributed application. 1.  Object namin

When should i use abstract classes and interfaces, When should I use abstra...

When should I use abstract classes and when should I use interfaces?  Use Interface, when: Design changing often or when various implementations only share method sign

Dijkstra''s algorithm, How can I convert Dijkstra''s algorithm to do max fl...

How can I convert Dijkstra''s algorithm to do max flow instead of min flow, and how can I implement it into Ford Fulkerson algorithm?

Develop the back end of a calculator application, For this assignment, you ...

For this assignment, you will develop the back end of a calculator application. The GUI (graphical user interface) has been provided by your instructor. The application will requir

Student, Your class must contain the followings (20 points):Code a simple c...

Your class must contain the followings (20 points):Code a simple class in JAVA classed “Student. · Variables (name, age, addressStreet, city, state, zip, country) ·

What do you mean through ftp or file transfer protocol, What do you mean th...

What do you mean through FTP or File Transfer Protocol? FTP: File transfer protocol was first introduced in the year of 1973; it standardized the transfer of files among comp

Queues, we can insert elements at rear and remove at front bt my question i...

we can insert elements at rear and remove at front bt my question is that how we insert at front in circular queue

What is meant through semantic error, What is meant through semantic error?...

What is meant through semantic error? It is an error that a developer encounters while a statement is executed but it was not intended through him (the developer). Such errors ar

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