Reference Data Types

In this section we will discuss about Reference Data Types in Java 7.

Reference Data Types

Reference Data Types

In this section we will discuss about Reference Data Types in Java 7.

Reference Data Types :

Non-primitive data types are also called reference data types. It is handled by reference. These refer to objects and arrays. it is created by defining constructor of a classes. You can use it to access the objects. Class objects and different type of array variables are described in reference data type.

You can define reference data type as a variable that can contain reference of dynamically created object. These are not predefined like primitive data type.
These are -

  • array
  • class
  • interface

Array Type :
In general, array is a collection of similar type of data types.

Syntax :

DataType[] arrayVariable=new DataType[];

Example :

int[] n=new int[5];
String[] str=new String();

class Type :

Class is a template of variables and methods. Name of class refers as a type in java. By creating object of this class you can access class variables and methods.

Example :

Test.java

class Test{
int a=100;
public void display(){
System.out.println("Value of a:" +a);
}
}

MainClass.java

Class MainClass{
public static void main(String[] args){
Test test=new Test();
test.display();
}
}

Interface Type:
The another type of reference data type is Interface Type. It supports concept of multiple inheritance. You can use name of interface as type of reference.