Final Java Basics Review

Source: Internet
Author: User

//inheritance Disadvantage: Break the encapsulation. /*Final keyword: 1,final is a modifier that can be used to modify classes, methods, and variables. 2,final-Modified classes cannot be inherited. 3,final-Modified methods cannot be overridden.    A variable modified by 4,final is a constant that can be assigned only once. Why use final modifier variables.    In fact, in the program if a data is fixed, then the direct use of this data can be, but so poor reading, so it is the name of the data.    And the value of this variable name cannot be changed, so add final fixed. Specification: Constant All letters are capitalized, multiple words, in the middle with _ connection. */classfu{/*Final*/ voidmethod () {//The resources of the underlying system are called.     }}classZiextendsfu{ Public Static Final DoubleMY_PI = 3.14; Static Final intx = 7; voidmethod () {//Final int x = 9;//x = 9;        Final intNumber = 9;    System.out.println (MY_PI); }}classFinaldemo { Public Static voidMain (string[] args) {System.out.println ("Hello world!"); }}

Inheritance disadvantage: Break the encapsulation.
/*
Final keyword:
1,final is a modifier that can be used to modify classes, methods, and variables.
2,final-Modified classes cannot be inherited.
3,final-Modified methods cannot be overridden.
A variable modified by 4,final is a constant that can be assigned only once.

Why use final modifier variables. Actually in the program if a data is fixed,
So it is possible to use this data directly, but the reading is poor, so it has the name of the data.
And the value of this variable name cannot be changed, so add final fixed.

Specification: Constant All letters are capitalized, multiple words, in the middle with _ connection.



*/
Class Fu
{
/*final*/void Method ()
{
The resources of the underlying system are called.
}
}
Class Zi extends Fu
{
public static final Double my_pi = 3.14;
static final int x = 7;

void Method ()
{
Final int x = 9;
x = 9;
Final int number = 9;

System.out.println (MY_PI);
}
}

Class Finaldemo
{
public static void Main (string[] args)
{
System.out.println ("Hello world!");
}
}

Final Java Basics Review

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.