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

What do you understand by private and public class, What do you understand ...

What do you understand by private, protected and public? These are accessibility modifiers. Private is the most restrictive, whereas public is the least restrictive. There is n

Padovan String, A Padovan string P(n) for a natural number n is defined as:...

A Padovan string P(n) for a natural number n is defined as: P(0)=''X'' P(1)=''Y'' P(2)=''Z'' for a string characters ''X'',''Y'',''Z'' only,and given value of n,write a program th

Describe the life cycle methods of a jsp? , 1. Pre-translated: Before the...

1. Pre-translated: Before the JSP file has been compiled and translated into the Servlet. 2. Translated: The JSP file has been compiled and translated as a Servlet. 3. I

Explain subclasses and polymorphism, Explain Subclasses and Polymorphism ? ...

Explain Subclasses and Polymorphism ? Car and Motorcycle are subclasses of MotorVehicle. If you instantiate a Car or a Motorcycle along with new, you can use in which object a

Map objects to a relational database? , Due to impedance mismatch between r...

Due to impedance mismatch between relational technology and object you need to understand the progress of mapping classes (objects) and their relationships to tables and relationsh

What is heuristic, What is heuristic? Heuristic is a procedure which co...

What is heuristic? Heuristic is a procedure which commonly, but not always, works or that provides nearly the right answer.

How is method overriding different from method overloading, How is method o...

How is method overriding different from method overloading? Overriding involves the creation of two or more concepts with the same name and same signature in different classes

Area under curve , what will be the logic? in C program #include ...

what will be the logic? in C program #include float start_point, /* GLOBAL VARIABLES */ end_point, total_area; int numtraps; m

Rfid based student attendance system include biometrics, Develop a rfid bas...

Develop a rfid based student attendance system include biometrics Project Description: The aim of our project is using rfid technology student attendance has to be taken. whe

Design a website in java using xml, The design of the website will be left ...

The design of the website will be left to the individual student. The website must be written only in xml, displayed in xhtml using transforms and xsl for styling elements. Javascr

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