Exam 1 Review

Here are some sample exam questions:
  1. Explain the main parts of a method header.
  2. Write a method that takes as input an array of integers and returns the sum of all elements in the array.
  3. What is the output produced by the following code fragment:
    String s = "1|2|3|4";
    String[] theSplitString = s.split("2");
    System.out.print(theSplitString);
    A.    [Ljava.lang.String;@8813f2
    B.    Error – ArrayIndexOutOfBoundsException
    C.    1|
    D.    3 4
  4. True or False: A method can be declared static.
  5. True or False: All classes should provide getters and setters for all data members.
  6. Explain the difference between == and .equals.
  7. Identify at least two errors in the following class definition.

    public class Score {
    private String initials;
    private int score;

    public Score(String initials, int score) {
    this.initials = initials;
    score = score;
    }

    public String getScore() {
    return score;
    }

    }


Comments