JAVA questions as highlted 26. Two objects, objectA and objectB, are objects in
ID: 3744226 • Letter: J
Question
JAVA questions as highlted
26. Two objects, objectA and objectB, are objects in the class Listing. The object objectA is copied to objectB. How many objects exist after the copy, if the copy is performed as:
(a) a deep copy?
(b) a shallow copy?
27. Of the two types of copies discussed in the previous exercise, which one produces a clone (an exact duplicate of an existing object)?
28. Give the signature of a method named deepCopy, that clones an object in the class Listing sent to it as a parameter and returns a reference to the clone.
29. Give the Java invocation to clone the object objectA (using the method discussed in the previous exercise) and store a reference to the clone in the variable: newListing.
Most of this questions are answerd but not only those are not and is not clear to understand
19. Half of the integers stored in the array data are positive, and half are negative. Determine the absolute speed of the following algorithm, assuming: the time to execute a memory access is 100 nanoseconds and that all other operations (arithmetic, register accesses, etc.) take 10 nanoseconds. for(int i 0; iExplanation / Answer
19.
since there are 1000000(lets say N) elements in data array and half of them 500000 are positive and 500000 are negetive number.
Since for every element memory read is needed, N number of memory access.therefore N*100 nanosecond
and All N elements are compare to check whether it is negetive or not (therefore N*10 nanosecod).
since N/2 elements are negetive so, N/2 number of meromy write is needed, therefore (N/2*100) nanosecond
so total time taken = (N*100)+(N*10)+(N/2*100)
=> N(100+10+50)
=>N*160
since N=1000000 therefor N*160= 160*1000000 => 160000000ns
26.
1st Shallow copy : Since ObjectA is Copied to ObjectB by Shallow(means both are same Object with different name, that means One object now named as ObjectA and ObjectB).
since ObjectA and ObjectB are now single Object therefore now only Two object exists now.
2nd Deep copy: Deep copy makes copies of dynamically allocated memory pointed to by the fields. that means If objectA is Copied to ObjectB, means both are completly different object, they have no connection.Deep copy produces a clone (an exact duplicate of an existing object). so now total number of object 3
27.
As i already mentioned in Deep Copy produces a clone (an exact duplicate of an existing object).
28.
29.
Listing & Listing(Listing &object)
{
return *this
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.