Understanding Reference data type – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Code Learning #JAVA#3859    siteicon   siteicon  

Understanding Reference data type

Reference data type for class object reference and array reference.

Learning Objectives

  • Understanding class object as a reference data type.
  • Understanding array name as a reference data type.

Source Code

TC++ #3859

Source Code

Run Output

1, 2

Note: The second line could be different in your case as it is just a memory reference

Code Understanding

class RefDataType
int rd=5;
This is declared outside main as it would be referred using the class object.

public static void main(String[] args)
RefDataType robj = new RefDataType();
Here robj is simply a reference to the memory area reserved for class based references.

The reference data type has been used to reference to primitive data in the reference object.

int ar[]={1,2};
Here the array name ar is also a reference to memory location.

Here the memory location reference is referred so you may get some output which is different in each case as a different location would be referred to.

System.out.println(ar[0]+”, “+ar[1]);
Here the actual value at the given location pointed by 0th and 1st location in the memory reference are being printed.



Suggested Filename(s): RefDataType.java


sunmitra| Created: 20-Mar-2018 | Updated: 20-Mar-2018|