Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please give detail explanation. no copy and paste from internet!!!!1 Object vari

ID: 3822171 • Letter: P

Question

please give detail explanation. no copy and paste from internet!!!!1

Object variables in Java are a hybrid of pointer and reference variables. Given the following code fragment. Car myCar, his Car; float s; myCar = new Car (ellipsis); his car = myCar s = his Car. speed(); There are two applied occurrences for each of the variables "myCar" and "hisCar". State and explain if each occurrence behaves as pointer or reference variables. Reference variables in the Perl language are actually pointer variables. Explain why using example code fragments.

Explanation / Answer

HI, I have answered first part.

I do not know perl so i can not answer other part.

c)
   Car myCar, hisCar;
   float s;

   myCar = new Car(...);
   ...
   hisCar = myCar;

   s = hisCar.speed();

   So, in Java reference variables points to object that is stored in heap.

   So, here myCar pointing to a new object.

   So, myCar is like pointer.

   Now, hisCar is pointing to same object that myCar is pointing

   So, hisCar is like reference variable.