博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
大数据 java 代码示例_Java变量类型与示例
阅读量:2530 次
发布时间:2019-05-11

本文共 2294 字,大约阅读时间需要 7 分钟。

大数据 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变量有三种类型

  1. Instance Variables

    实例变量

  2. Local Variables

    局部变量

  3. 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 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.

    我们只能在一个块中使用这些变量。

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)类变量/静态变量 (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

翻译自:

大数据 java 代码示例

转载地址:http://imxzd.baihongyu.com/

你可能感兴趣的文章
Python 模块之_os模块_os是与操作系统交互的接口
查看>>
通通玩blend美工(1)——荧光Button
查看>>
[UWP]了解模板化控件(8):ItemsControl
查看>>
使用JustDecompile修改程序集
查看>>
SQLServer 分组查询相邻两条记录的时间差
查看>>
Swift语言指南(一)--语言基础之常量和变量
查看>>
关于webpack的使用
查看>>
Windows 2008 R2上配置IIS7或IIS7.5中的URLRewrite(URL重写)实例
查看>>
浅析java垃圾回收机制
查看>>
彻底理解线性筛选法
查看>>
Java Socket总结
查看>>
法语学习笔记
查看>>
使用css的类名交集复合选择器 《转》
查看>>
[USACO18DEC]The Cow Gathering
查看>>
情感分析-英文电影评论
查看>>
王者荣耀游戏服务器架构的演进读后感
查看>>
关于ajax请求controller返回中文乱码的解决方法!
查看>>
Objective-C 和 Core Foundation 对象相互转换的内存管理总结
查看>>
IOS音频1:之采用四种方式播放音频文件(一)AudioToolbox AVFoundation OpenAL AUDIO QUEUE...
查看>>
Linux nmon 命令
查看>>