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

Develop an android app for me, Project Description: I need someone to pr...

Project Description: I need someone to prepare an android app for me and provide it to me asap. The app details to be provided on pm Skills required: Java, Android

1. Create a text file (you can name it sales.txt) that conta, 1. Create a t...

1. Create a text file (you can name it sales.txt) that contains in each line the daily sales of a company for a whole month. Then write a Java application that: a. asks the user fo

Explanation of the inputstream with suitable diagrams, Problem 1) Descr...

Problem 1) Describe the concept of interfaces in Java with a suitable example for the same Explanation of the concept of interfaces with example 2) Describe the Inp

Spring framework, Spring framework The Spring framework is the leading...

Spring framework The Spring framework is the leading full-stack J2EE /JAVA application framework. Not like other applications, Spring does not expose itself on the design of a

Difference hashcode and equal, The hashCode() and equals() methods have...

The hashCode() and equals() methods have to be very important, when objects implementing these two functions are added to collections. If not implemented or implemented incorre

Digital clock, how to Using polymorphism to write a program to display digi...

how to Using polymorphism to write a program to display digital clock?

Illustrate RUP? , Rational Unified Process (RUP) is a normal framework ...

Rational Unified Process (RUP) is a normal framework that may be used to define a development process. The software development life cycle has got 4 parts in the following o

Program to calculates the number of unique shapes, 1. Write the code for th...

1. Write the code for the method that calculates the number of unique shapes for a binary search tree with n nodes. Use the formula  where b n is the number of possible sh

Android Development Project, Task I have an Android mobile app project tha...

Task I have an Android mobile app project that I''m trying to get profiles to transfer by connecting to a server at 23.23.175.213 port 1337. I have to send a json string to the se

What is the use of message object, Message is a light weight message having...

Message is a light weight message having only header and properties and no payload. Therefore if the If the receivers are to be notified about an event, and no data requires to be

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