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 how many ways businesses monitor their employees, Explain how many ...

Explain how many ways businesses monitor their employees? • Systems are available which monitor almost every key stroke that an employee forms on a computer. • Systems are avai

What are the implicit objects in jsp, Implicit objects are formed by the we...

Implicit objects are formed by the web container and have information related to a particular request, page, or application. They are request, response, pageContext, session, appli

Programming Assignment : Trains, I CANNOT FAIL THIS I NEED IT FRIDAY TASK...

I CANNOT FAIL THIS I NEED IT FRIDAY TASK 1 : Read The definition of the Item interface and implement TrainCar Your are being provided with 1. Item.java 2. Automobile.java 3.

GUI, How can I connect my java application with xampp

How can I connect my java application with xampp

What is arithmetic promotion assignment and casting, What is Arithmetic pro...

What is Arithmetic promotion assignment and casting? In an assignment statement, i.e. if there's an equals sign, Java compares the type of the left hand side to the at last typ

Swing, can we develop paint user can draw his charcters and images in swing...

can we develop paint user can draw his charcters and images in swing

Rest client, Modify both of the above clients (to write separate clients) t...

Modify both of the above clients (to write separate clients) to extract the exchange rate from a live web service that performs currency conversion. You can choose a Java or a .NET

What is java bytecode, What is java Bytecode Java programs (Source code...

What is java Bytecode Java programs (Source code) are compiled into a form known as Java bytecodes. Java compiler reads Java language source (.java) files, translates source

Explain labeled loops in details, Explain Labeled Loops in details ? Ge...

Explain Labeled Loops in details ? Generally inside nested loops break and continue exit the innermost enclosing loop. For instance consider the subsequent loops. for (int i=1

File and random access file classes, Difference between the File and Random...

Difference between the File and Random Access File classes? Ans) The File class encapsulates the files and directories of the local file system. The Random Access File class giv

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