What is initializing fields, JAVA Programming

Assignment Help:

What is Initializing Fields ?

Fields can (and often should) be initialized while they're declared, just like local variables.
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

}
The next program creates a new car and prints it:
class CarTest2 {

public static void main(String[] args) {

Car c = new Car();

System.out.println(c.licensePlate + " is moving at " + c.speed +
"kilometers per hour.");
}
}
For example,
$ javac Car.java
$ javac CarTest2.java
$ java CarTest
is moving at 0.0 kilometers per hour.


Related Discussions:- What is initializing fields

How to retrieve warnings, SQLWarning objects are a subclass of SQLException...

SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the implementation of an application, as exceptions do; they easily

Currency calculator, I have to write a several line currency exchange rate ...

I have to write a several line currency exchange rate calculator.it wants me to use a variable and prompt var dollarAmount = Prompt("Enter amount in U.S. dollars:"); and give t

Define in detail the building of webpage, Question 1 Describe the browser ...

Question 1 Describe the browser components and its features Question 2 Define in detail the building of webpage Question 3 How to use forms? Describe with an example

Explain multi dimentional arrays in java, Explain multi dimentional arrays ...

Explain multi dimentional arrays in java? So far all these arrays have been one-dimensional. That is, a single number could locate any value in the array. Therefore sometimes d

Advantage of event-delegation over event-inheritance model, Describe advant...

Describe advantage of the event-delegation model over the earlier event-inheritance model ?

Array to store 10messages of type String., Ask1. Storing the Array: Write a...

Ask1. Storing the Array: Write an application that uses an Array to store 10messages of type String. You will store this Array with 10 messages of your choosing. For example, a mes

Write a java code to draw ovals and circles, Write a java code to draw Oval...

Write a java code to draw Ovals and Circles? Java has techniques to draw outlined and filled ovals. As you'd probably guess these methods are called drawOval() and fillOval() c

Design a scheduler in java, Your task is to design a scheduler for the Sher...

Your task is to design a scheduler for the Sheridan Rail Corporation which keeps track of all daily scheduled trips for the railway.  Users can add new trips as well as perform sea

Describe the class or static members, Describe the Class or static Members ...

Describe the Class or static Members ? A method or a field in a Java program could be declared static. That means the member belongs to the class rather than to an individual

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