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

Conditional statements in javascript, Very frequently when you write code, ...

Very frequently when you write code, you desire to perform distinct actions for different decisions. You can employ conditional statements in your code to do this. In JavaScript

Time date millis method, I neeed to create a basic code to do the following...

I neeed to create a basic code to do the following. the class is entry level and I would appreciate a brief explanation as to why you do each bit. Write a program that displays t

Control graphical user interface elements, Introduction In this assign...

Introduction In this assignment you will use Processing to create some geometric objects and graphical user interface (GUI) elements that Processing itself lacks. Processing h

What is the function of network interface card, What is the function of Net...

What is the function of Network Interface Card? NIC is an I/O device which plugs within the computer and it enables it to communicate over a network.

Dropbox calendar, code in dropbox calendar and loop for feruary leapyear

code in dropbox calendar and loop for feruary leapyear

Explain what occur when an object is created in java, Explain what occur wh...

Explain what occur when an object is created in Java?

Code for calculatr, how i made a calculator in java plz tell help me

how i made a calculator in java plz tell help me

Project, How can i draw E-R diagram

How can i draw E-R diagram

Explain the java.net package, Explain The java.net package Each package...

Explain The java.net package Each package describes a number of classes, interfaces, exceptions, and errors. For instance, the java.net package contains these, classes, interfa

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