Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the object-oriented final keyword of Java

Shulou Source: shulou.com Published: 2022-06-02 04:45:14 10月02日 Update

This article mainly introduces the Java object-oriented final keyword how to use, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

/ * * knowledge points: final keyword 1. What is final: final is the final meaning 2. The variable modified by the final keyword cannot be modified by a constant. The method modified by the final keyword cannot be overridden by a subclass. The class modified by the final keyword cannot be inherited by * / public class FinalKeyword {public static void main (String [] args) {final double PI = 3.14 System.out.println (PI); / / instantiate father Father f = new Father (); f.work (); / / instantiate son Son s = new Son (); s.study () }} / / Father class Father {public final void work () {System.out.println ("doing farm work"); / / son class Son extends Father {public void study () {System.out.println ("study hard and make progress every day") }} / daughter final class Daughter extends Father {} / grandson class GranSon extends Son {} Thank you for reading this article carefully. I hope the article "how to use the final keyword of Java object-oriented" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Keywords articles objects sons examples fathers knowledge learning daily progress values interests farm work variables at the same time daughters subcategories that is constant meaning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker macOS NVidia Redmi MySQL