Java中的用户定义数据类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30867364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
User defined data types in Java?
提问by Shetty's
Recently I attended an interview, where I was asked,
最近我参加了一个面试,被问到,
What are user-defined data types in Java?
Java 中的用户定义数据类型是什么?
I answered that variables declared using class type are user-defined. But I am not convinced with my answer. I feel class type is Reference data type/Object data type.
我回答说使用类类型声明的变量是用户定义的。但我并不相信我的回答。我觉得类类型是Reference data type/Object data type。
As per there are two types:
按类型分为两种:
- Primitive data types [int,float..etc].
- Reference type/Object type[String str, user_defined_Class Obj1..etc]
- 原始数据类型 [int,float..etc]。
- 引用类型/对象类型[String str, user_defined_Class Obj1..etc]
I did search on this, but couldn't get a proper answer.
我确实对此进行了搜索,但无法得到正确的答案。
Kindly shed some light on this.
请对此有所了解。
回答by gprathour
I would like to go in detail on this.
我想详细谈谈这个。
Firstly Java is a strongly typed language i.e. before using any data we need to tell the complier of what data type this data will be.
首先,Java 是一种强类型语言,即在使用任何数据之前,我们需要告诉编译器该数据将是什么数据类型。
In simple words we need to declare the data type of the variable.
简单来说,我们需要声明变量的数据类型。
Basically there are three type of data types:
基本上有三种类型的数据类型:
- Primitive data types
- Derived data types
- User defined data types
- 原始数据类型
- 派生数据类型
- 用户定义的数据类型
Primitive data typesare the general and fundamental data types that we have in Java and those are byte, short, int, long, float, double, char, boolean
.
原始数据类型是我们在 Java 中拥有的通用和基本数据类型,它们是byte, short, int, long, float, double, char, boolean
.
Derived data typesare those that are made by using any other data type for example, arrays.
派生数据类型是通过使用任何其他数据类型(例如数组)生成的数据类型。
User defined data typesare those that user / programmer himself defines. For example, classes, interfaces.
用户定义的数据类型是用户/程序员自己定义的数据类型。例如类、接口。
In very-very simple words I can say,
用非常非常简单的话我可以说,
int a
内部
Here a
is a variable of int data type.
这a
是一个 int 数据类型的变量。
MyClass obj
我的类对象
Here obj
is a variable of data type MyClass
and we call them reference variables as they can be used to store the reference to the object of that class.
这obj
是一个数据类型的变量,MyClass
我们称它们为引用变量,因为它们可用于存储对该类对象的引用。
回答by Ammad Amjad
user define datatype means that programmer defined him or her self like making classes or interface datatype
用户定义数据类型意味着程序员定义他或她自己,就像制作类或接口数据类型一样