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

Create an executable application in java, This assignment requires you to d...

This assignment requires you to design, implement and test a program using Java features from the first half of the subject content. You are required to implement in Java all the c

Develop a graphical display framework, Develop a Graphical Display Framewor...

Develop a Graphical Display Framework Project Description: The intent of this project is to prepare a web based graphical display framework that will display many data points

What is constructors and explain with an example, What is Constructors? Exp...

What is Constructors? Explain with an example? A constructor forms a new instance of the class. It initializes all the variables and does any work essential to prepare the clas

Activity diagram, The statechart diagrams and activity diagram are related ...

The statechart diagrams and activity diagram are related in a sense that statechart diagram refers on object undergoing a transition process and an activity diagram refers on the f

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

Describe the java collections framework? , Comparable interface: The "Com...

Comparable interface: The "Comparable" allows itself to compare with other same types of object. The function compareTo() is specified in the interface. Several of the standa

In which way java says write once run anywhere, Java says write once, run ...

Java says write once, run anywhere . In which ways this isn't quite applicable ?

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