Trace the following code segment and show its expected output. Normally when tra
ID: 668708 • Letter: T
Question
Trace the following code segment and show its expected output. Normally when tracing application code that uses an ADT you need not worry about the details of the code implementation. But for this exercise we want you to "wear the hat" of the implementer and carry your tracing down to the implementation level so that you can see exactly what is returned by the toString methods. Explain why the two StringLogs are not displayed in exactly the same way.
StringLogInterface info1;
StringLogInterface info2;
info1 = new ArrayStringLog ("Information 1");
info2 = new LinkedStringLog ("Information 2");
info1.insert("Tom");
info2.insert("Tom");
info1.insert("Julie");
info2.insert("Julie");
System.out.println(info1.toString());
System.out.println(info2.toString());
Explanation / Answer
OUTPUT :
Information 1
Tom
Julie
Information 2 Tom Julie
The two StringLogs are not displayed in exactly the same way because one string is an array string log and the other is of the linked string log.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.