SE 450 Section 103 Fall 2001/2002
Midterm Review

Review of Topics Covered

Midterm Review Problems

  1. Explain why main is a static method (for apps) while applet methods (init, start, ... ) are not static.
    answer

  2. What will this code print? Explain your answer. String s1 = "abc"; String s2 = new String("abc"); String s3 = s1; if (s1 == s2) System.out.println("s1 == s2"); if (s1 == s3) System.out.println("s1 == s3"); How can we test that s1 and s2 are equal?
    answer

  3. What will this code print? Explain your answer. StringBuffer s1 = new StringBuffer("abcde"), s2 = s1; s2.setCharAt(2,'z'); System.out.println(s1); System.out.println(s2);
    answer

  4. What output does this app produce? Explain your answer. public class A { public static void main(String[ ] s) { B var1 = new C(); B var2 = new B(1); System.out.println(var1); System.out.println(var2); } } class B { private int b; public B(int b) { this.b = b; } public String toString() { return "B: " + b; } } class C extends B { private int c; public C() { super(1); this.c = 3; } public String toString() { return "C: " + c; }
    answer

  5. Write an applet that places a button and a label on the screen. The button should sit on the top of the applet and the label should be at the bottom of the applet. When the user clicks the button (labeled "Click Me!"), the text in the label changes from "Nothing Yet!!!" to "Clicked!!".
    Here is an example.
    answer