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

Oop, creating a point of sale

creating a point of sale

Polymoethism, write a java program to test for class Person Student facult...

write a java program to test for class Person Student faculty Employee

Describe exception handling in java, Question A What are the difference be...

Question A What are the difference between an interface and an abstract class? Question B Describe Exception Handling in JAVA Question C Describe the following with resp

Object and Instance, What is the difference between instance and object of ...

What is the difference between instance and object of a class? Few says both are same, then why java kept both the words for same thing?

How marketing strategies are changed along with the progress, How marketing...

How marketing strategies are changed along with the progress in computing? How latest marketing strategies are implemented? Marketing Strategy Changes along with the latest req

Give an examples of access protection, Give an Examples of Access Protectio...

Give an Examples of Access Protection ? This is how the Car class would almost certainly be written in practice. Remember that all the fields are now declared private, and the

Authentication -security component, Authentication is basically an identifi...

Authentication is basically an identification step. Functionality used for J2EE security: Principal : An entity that may be authenticated and identified. Principal n

Terminology, what is mearnt by a variable in java

what is mearnt by a variable in java

Synchronization and its importance, What do you mean by synchronization an...

What do you mean by synchronization and its importance?

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