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

I want software tool for sequential circuit analysis, I want Software Tool ...

I want Software Tool for Sequential Circuit Analysis The output of the program could be both graphical for the diagram and the rest is console. Skills required: C++ Progra

Linked list, Write a program that takes as input a sequence of transactions...

Write a program that takes as input a sequence of transactions of the form "buy x; share(s) at $y each" or "sell x share(s) at $y each," assuming that the transactions occur on con

Java Gui, Does the java applet using swing components, JAVA Programming on ...

Does the java applet using swing components, JAVA Programming on this contain all the source codes for download?

Explain any five buzz words in java, Question 1 Explain any five buzz w...

Question 1 Explain any five buzz words in Java 2 Explain exception classes and also explain common exceptions in java 3 Explain primitive and abstract data type in java

Basic difference b/w finalize(), 1.   final - it is a constant declarati...

1.   final - it is a constant declaration. 2.   finally - handles exception. The finally block is optional and gives a mechanism to clean up regardless of what occurs within

Describe synchronization in respect to multithreading, Describe synchroniza...

Describe synchronization in respect to multithreading. With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared res

Program to built canvas printing calculator, Printing Calculator Canv...

Printing Calculator Canvas Printing Calculator In this assignment we will continue to work on our canvas printing web service. Specifically we will make use of Javascrip

Javascript validarion, 1. Obtaining the new script: Download and save the a...

1. Obtaining the new script: Download and save the attached comment CGI mailer script form-mail2.pl to your server''s cgi-bin directory, and change the permissions on the script to

File I/O, Write a program that reads both the girl and boy files into memor...

Write a program that reads both the girl and boy files into memory using arrays. Then, allow the user to input a name. The program should search through both arrays. If there is

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