大数据 java 代码示例_Java变量类型与示例
大數據 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.
變量是用戶定義的存儲塊名稱,它們的值可以在程序執行期間隨時更改。 它們在類/程序中起著重要的作用,因為它們有助于存儲,檢索數據值。
Java中變量的類型 (Types of the variables in Java)
There are three types of Java variables,
Java變量有三種類型 ,
Instance Variables
實例變量
Local Variables
局部變量
Class/Static Variables
類/靜態變量
1)實例變量 (1) Instance Variables)
Instance variables are declared in a class but outside a Method, Block or Constructor.
實例變量在類中聲明,但在方法,塊或構造函數之外。
Instance variables have a default value 0.
實例變量的默認值為0 。
These variables can be created only when the object of a class is created.
僅當創建類的對象時才能創建這些變量。
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 Red2)局部變量 (2) Local Variables)
Local variables are the variables which are declared in a class method.
局部變量是在類方法中聲明的變量。
We can use these variables within a block only.
我們只能在一個塊中使用這些變量。
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 : 103)類變量/靜態變量 (3) Class Variables/Static Variables)
This can be called Both Class and Static Variable.
這可以稱為類和靜態變量 。
These variables have only one copy that is shared by all the different objects in a class.
這些變量只有一個副本,該副本由類中的所有不同對象共享。
It is created during the start of program execution and destroyed when the program ends.
它在程序執行開始時創建,并在程序結束時銷毀。
Its Default value is 0.
其默認值為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
大數據 java 代碼示例
總結
以上是生活随笔為你收集整理的大数据 java 代码示例_Java变量类型与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 板栗多少钱一斤啊?
- 下一篇: DNF狂暴者85刷图加点?