




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solutions for test 2 of cs 101 fall 2004, focusing on logical operations and variables. It includes truth tables, code segment outputs, and questions related to conditional statements and object instantiation.
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





public class A { private int v1; private int v2; public A(int f1, int f2) { this.v1 = f1; this.v2 = f2; } public String toString() { return "( v1 = " + v1 + " " + v2 + ")"; } }
public class B { private int b; public B() { System.out.println("b = " + b); } }
public Class C { private int c1; static private int c2; public C() { c1 = 0; c2 = 0; } public void increment() { ++c1; ++c2; } public String toString() { return "( c1 = " + c1 + " c2 = " + c2 + ")"; } }
int n1 = 12; int n2 = 144; if (n2 < n1) { n1 = 10; } System.out.println("n1 = " + n1);
n1 =
String s1 = "wahoo"; String s2 = "wahoo"; if (s2 == s1) { s1 = "UVA"; } System.out.println("s1 = " + s1);
s1 =
String s1 = new String("wahoo"); String s2 = new String("wahoo"); if (s2.equals(s1)) { s1 = "UVA"; } System.out.println("s1 = " + s1);
s1 =
C n1 = new C(); C n2 = new C(); n1.increment(); n2.increment() System.out.println( n1.toString() ); System.out.println( n2.toString() );
( c1 = c2 = )
( c1 = c2 = )
public class DemoB { public static void main(String[] args) { B b1 = new B(); B b2 = b1; int v = b1.b; System.out.println( v ); } }
public class DemoA { public static void main(String[] args) { A a = new A(); System.out.println( a ); } }
if (n == 1) { i = 1; } else { if (n != 2) { i = 2; } else { i = 3; } }
A a1 =
A a2 =