Shetty's
Shetty's

Reputation: 617

User defined data types in Java?

Recently I attended an interview, where I was asked,

What are user-defined data types in 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.

As per there are two types:

  1. Primitive data types [int,float..etc].
  2. Reference type/Object type[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.

Upvotes: 0

Views: 44948

Answers (4)

Sahil Panchal
Sahil Panchal

Reputation: 1

User Defined Data Type Class -> A class is a template that specifies the attributes and behavior of things or objects. -> A class is a blueprint or prototype from which creates as many desired objects as required.

Interface

-> An interface is a collection of abstract methods. -> A class implements an interface, thereby inheriting the abstract methods of the interface. -> An interface is not a class. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements. -> Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.

Upvotes: 0

pandu Patil
pandu Patil

Reputation: 11

In JAVA there are two types of data types are available, they are

   1. Primitive datatypes

   2. User Defined datatype

Basically, the primitive data types are predefined. like int, char, float, etc. if you want to store the data of types integer, character, then you can use these predefined datatypes happily. what if, if you want to store the data of your own type like Student, Employee, which is basically a combination of primitive datatypes, then here we have to go with user-defined data type, for this we can use Classes in java to store data of your own

Upvotes: 1

Ammad Amjad
Ammad Amjad

Reputation: 1

user define datatype means that programmer defined him or her self like making classes or interface datatype

Upvotes: -3

gprathour
gprathour

Reputation: 15333

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.

In simple words we need to declare the data type of the variable.

Basically there are three type of data types:

  1. Primitive data types
  2. Derived data types
  3. User defined data types

Primitive data types are the general and fundamental data types that we have in Java and those are byte, short, int, long, float, double, char, boolean.

Derived data types are those that are made by using any other data type for example, arrays.

User defined data types are 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.

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.

Upvotes: 3

Related Questions