日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

大数据 java 代码示例_Java变量类型与示例

發(fā)布時(shí)間:2023/12/1 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 大数据 java 代码示例_Java变量类型与示例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

大數(shù)據(jù) java 代碼示例

Java變量 (Java variables)

Variables are the user-defined names of the memory blocks, and their values can be changed at any time during program execution. They play an important role in a class/program as they help in to store, retrieve a data value.

變量是用戶定義的存儲(chǔ)塊名稱,它們的值可以在程序執(zhí)行期間隨時(shí)更改。 它們?cè)陬?程序中起著重要的作用,因?yàn)樗鼈冇兄诖鎯?chǔ),檢索數(shù)據(jù)值。

Java中變量的類型 (Types of the variables in Java)

There are three types of Java variables,

Java變量有三種類型 ,

  • Instance Variables

    實(shí)例變量

  • Local Variables

    局部變量

  • Class/Static Variables

    類/靜態(tài)變量

  • 1)實(shí)例變量 (1) Instance Variables)

    • Instance variables are declared in a class but outside a Method, Block or Constructor.

      實(shí)例變量在類中聲明,但在方法,塊或構(gòu)造函數(shù)之外。

    • Instance variables have a default value 0.

      實(shí)例變量的默認(rèn)值為0 。

    • These variables can be created only when the object of a class is created.

      僅當(dāng)創(chuàng)建類的對(duì)象時(shí)才能創(chuàng)建這些變量。

    Example:

    例:

    public class Bike {public String color;Bike(String c) {color = c;}public void display() {System.out.println("color of the bike is " + color);}public static void main(String args[]) {Bike obj = new Bike("Red");obj.display();} }

    Output

    輸出量

    Color of the bike is Red

    2)局部變量 (2) Local Variables)

    • Local variables are the variables which are declared in a class method.

      局部變量是在類方法中聲明的變量。

    • We can use these variables within a block only.

      我們只能在一個(gè)塊中使用這些變量。

    Example:

    例:

    public class TeacherDetails {public void TeacherAge() {int age = 0;age = age + 10;System.out.println("Teacher age is : " + age);}public static void main(String args[]) {TeacherDetails obj = new TeacherDetails();obj.TeacherAge();} }

    Output

    輸出量

    Teacher age is : 10

    3)類變量/靜態(tài)變量 (3) Class Variables/Static Variables)

    • This can be called Both Class and Static Variable.

      這可以稱為類和靜態(tài)變量 。

    • These variables have only one copy that is shared by all the different objects in a class.

      這些變量只有一個(gè)副本,該副本由類中的所有不同對(duì)象共享。

    • It is created during the start of program execution and destroyed when the program ends.

      它在程序執(zhí)行開始時(shí)創(chuàng)建,并在程序結(jié)束時(shí)銷毀。

    • Its Default value is 0.

      其默認(rèn)值為0 。

    Example:

    例:

    public class Bike {public static int tyres;public static void main(String args[]) {tyres = 6;System.out.println("Number of tyres are " + tyres);} }

    Output

    輸出量

    Number of tyres are 6

    翻譯自: https://www.includehelp.com/java/variables-types-with-examples.aspx

    大數(shù)據(jù) java 代碼示例

    總結(jié)

    以上是生活随笔為你收集整理的大数据 java 代码示例_Java变量类型与示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。