Understanding Reference data type – CSKC
Sign In

Search

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

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test Java

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.

System.out.println(robj.rd);
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.

System.out.println(ar);
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.

}
}

Notes


Suggested Filename(s): RefDataType.java



Share

Created: 20-Mar-2018 16:08 | Updated: 20-Mar-2018 16:08|