Explain final fields, JAVA Programming

Assignment Help:

Explain final fields ?

You may also declare fields to be final. This is not the similar thing as declaring a method or class to be final. While a field is declared final, it is a constant that will not and cannot change. It can be set once (for instance when the object is constructed, other than it cannot be changed after that.) Attempts to change it will produce either a compile-time error or an exception (depending on how sneaky the attempt is).

Fields in which are both final, static, and public are effectively named constants. For example a physics program might describe Physics.c, the speed of light as
public class Physics {

public static final double c = 2.998E8;
}
In the SlowCar class, the speedLimit field is likely to be both final and static by it's private.
public class SlowCar extends Car {

private final static double speedLimit = 112.65408; // kph == 70 mph

public SlowCar(String licensePlate, double speed, double maxSpeed,
String make, String model, int year, int numberOfPassengers, int numDoors) {
super(licensePlate,
(speed < speedLimit) ? speed : speedLimit,
maxSpeed, make, model, year, numberOfPassengers, numDoors);
}

public void accelerate(double deltaV) {

double speed = this.speed + deltaV;

if (speed > this.maxSpeed) {
speed = this.maxSpeed;
}

if (speed > speedLimit) {
speed = speedLimit;
}

if (speed < 0.0) {
speed = 0.0;
}
this.speed = speed;

}

}


Related Discussions:- Explain final fields

While statement in java, The while statement define a loop that iterates as...

The while statement define a loop that iterates as long as condition remains true. In the following instance the control waits till the value of a text field becomes "go":

Create an android application., We need to create an Android application. T...

We need to create an Android application. The application is about registering courses in a university, viewing grades, available courses and evaluating faculty members. Advisor

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 an aspect, An aspect is the cross-cutting functionality that you ar...

An aspect is the cross-cutting functionality that you are executing. It is the aspect of your application you are modularizing. An example of an aspect is logging. Logging is somet

Please answer this, Assignment Help >> JAVA Programming Learning Outcomes:...

Assignment Help >> JAVA Programming Learning Outcomes: 1. Use different program control statements in a programming language 2. Demonstrate the use of arrays with a programming

How would you interact between servlets and applets? , We may use the java...

We may use the java.net.URL and java.net.URLConnection classes to start a standard HTTP connection and "tunnel" to a Web server. The server then gives this information to the s

Implement a java class, Your first task is to implement the Movie class to ...

Your first task is to implement the Movie class to store all the relevant information on a single DVD Movie, including its catalog number, title, year of release, rating, rental pe

#title.swithcase, 2. Problem Description: A Java program needs to be writte...

2. Problem Description: A Java program needs to be written to display the result of following operations based input character. The table for input character with operations is : I

Difference b/w a static variable and an instance variable?, Class variables...

Class variables are named as static variables. There is only single occurrence of a class variable per JVM per class loader. When a class is operated the class variables are in

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