100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Test Bank For Building Java Programs: A Back to Basics Approach 5th Edition All Chapters - 9780135472118 $49.99   Add to cart

Exam (elaborations)

Test Bank For Building Java Programs: A Back to Basics Approach 5th Edition All Chapters - 9780135472118

 8 views  0 purchase
  • Course
  • Unknown
  • Institution
  • Unknown

Test Bank For Building Java Programs: A Back to Basics Approach 5th Edition All Chapters

Preview 4 out of 233  pages

  • September 30, 2024
  • 233
  • 2022/2023
  • Exam (elaborations)
  • Questions & answers
  • Unknown
  • Unknown
avatar-seller
zusukihihi
,TestBank For Building Java Programs: A Back to Basics Approach 5th Edition
Final 1


Sample Final Exam #1
(Spring 2005; thanks to Stuart Reges)

1. Array Mystery
Consider the following method:

public static void arrayMystery(int[] a) {
for (int i = 1; i < a.length; i++) {
a[i] = i + a[i - 1] - a[i];
}
}

Indicate in the right-hand column what values would be stored in the array after the method arrayMystery executes
if the integer array in the left-hand column is passed as a parameter to it.



Original Contents of Array Final Contents of Array

int[] a1 = {7};
arrayMystery(a1); _____________________________

int[] a2 = {4, 3, 6};
arrayMystery(a2); _____________________________

int[] a3 = {7, 4, 8, 6, 2};
arrayMystery(a3); _____________________________

int[] a4 = {10, 2, 5, 10};
arrayMystery(a4); _____________________________

int[] a5 = {2, 4, -1, 6, -2, 8};
arrayMystery(a5); _____________________________




1

,TestBank For Building Java Programs: A Back to Basics Approach 5th Edition
Final 1


2. Reference Semantics Mystery
The following program produces 4 lines of output. Write the output below, as it would appear on the console.

public class BasicPoint {
int x;
int y;

public BasicPoint() {
x = 2;
y = 2;
}
}

public class ReferenceMystery {
public static void main(String[] args) {
int a = 7;
int b = 9;
BasicPoint p1 = new BasicPoint();
BasicPoint p2 = new BasicPoint();

addToXTwice(a, p1);
System.out.println(a + " " + b + " " + p1.x + " " + p2.x);

addToXTwice(b, p2);
System.out.println(a + " " + b + " " + p1.x + " " + p2.x);
}

public static void addToXTwice(int a, BasicPoint p1) {
a = a + a;
p1.x = a;
System.out.println(a + " " + p1.x);
}
}




2

, TestBank For Building Java Programs: A Back to Basics Approach 5th Edition
Final 1


3. Inheritance Mystery
Assume that the following classes have been defined:

public class A extends B { public class C {
public void method2() { public String toString() {
System.out.print("a 2 "); return "c";
method1(); }
}
} public void method1() {
System.out.print("c 1 ");
public class B extends C { }
public String toString() {
return "b"; public void method2() {
} System.out.print("c 2 ");
}
public void method2() { }
System.out.print("b 2 ");
super.method2(); public class D extends B {
} public void method1() {
} System.out.print("d 1 ");
method2();
}
}

Given the classes above, what output is produced by the following code?

C[] elements = {new A(), new B(), new C(), new D()};
for (int i = 0; i < elements.length; i++) {
System.out.println(elements[i]);
elements[i].method1();
System.out.println();
elements[i].method2();
System.out.println();
System.out.println();
}




3

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller zusukihihi. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $49.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75323 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$49.99
  • (0)
  Add to cart