Wednesday, July 13, 2016

Keyword final

In Java, keyword final has three functions, as follows:
  • When used to declare a variable, then the value of the variable can not be changed.
  • When used to declare a method, then the method can not be overridden by derived class.
  • When used to define a class, then the class can no longer be derived to new class.

Here, the point which we will discuss only the first point only. Second and third points will be discussed later in next post, when we talk about inheritance to a derived class.

If we want to use keyword final to declare a variable as a constant, then we need to fill the value into the variable. The value will be fixed or can not be changed during the execution of the program. Here is the general form of the declaration of a constant in Java:

access-modifier final data-type constant-name = value;

Just as in C/C ++, in Java, constants are generally written in capital letters. Here are some examples of declaring constants:

final double PI = 3.1416;
private final int ERROR = -1;
private final int ENGLISH = 1;
private final int ARABIC = 0;
private final String FILE_MENU_TITLE = "File";
private final String EXIT_BUTTON_TITLE = "Exit";

2 comments:

  1. Thank You for Sharing valuable information with us.

    E-Commerce is the fastest-growing platform which is becoming more demandable day by day this is a tremendous form of the vibrant sector that is bringing several opportunities to the new generation to become more skilled and professional. Taking up this great advantage in the E-Commerce sector would need the right path and the right skillset you need to learn the latest technologies and high-demand skills such as building payment gateways and developing an accessible and easy website along with the basics of E-commerce that‘s why Aptech learning official Pro E-Commerce training program in Dwarka, Janakpuri, and Gurgaon which will help to make a successful career in this booming industry. Java Programming Course helps to become an expert in Java web application development. It helps you to bring efficiency in collecting and analyzing the data through Java programming in this course you will learn effective web UI/UX design and Secure web applications by using the advanced technologies of the Java program.

    For more details please visit our website : Aptech Janakpuri

    ReplyDelete