GoConqr has a new look! Let us know what you think.

Quiz

All Mix EECS 2030

Muhammad Khan 39 questions

Take the quiz

Questions in this quiz (39)

  1. 1Consider the following class:
    public class A {
    public static int x = 0;
    public int y;
    public A() {
    this.y = 0;
    }
    }
    Suppose that you have a reference of type A:
    A a = new A();
    Which of the following is legal but considered bad style?
    1. Aa.x = 1;
    2. Ba.y = 1
    3. CA.x = 1;
    4. DA.y = 1;
  2. 2What is true about the expression x.compareTo(y) if x is an instance of a type that implements the
    comparable interface?
    1. Ax.compareTo(y) returns a postive integer if x is less than y
    2. Bx.compareTo(y) returns a postive integer if x is equal to y
    3. Cx.compareTo(y) returns a postive integer if x is greater than y
    4. Dx.compareTo(y) must return 0 if x is equal to y
  3. 3What is the difference between x.equals(y) and x == y for two references x and y?
    1. Ax == y does not compile
    2. Bequals compares equality of state and == compares equality of addresses
    3. Cequals compares equality of addresses and == compares equality of state
    4. Dthere is no difference
  4. 4What are the parts of a method signature?
    1. Amethod name and return type
    2. Bmethod name and list of parameter types
    3. Cmethod name, list of parameter types, and return type
    4. Dmethod name, modifiers, list of parameter types, and return type
  5. 5Consider the following code fragment:
    /**
    * This method does something
    *
    * @param i an integer
    * @pre. i>=0
    */
    public void method(int i) {
    /* method body not shown */
    }
    1. AIn the method body, the implementer has to throw an exception when i is smaller than zero
    2. BIn the method body, the implementer has to take the absolute value of i to ensure that its
      value is greater than or equal to zero.
    3. C. In the method body, the implementer has to set i to zero whenever the value of i is smaller
      than zero.
    4. DNone of the above.
  6. 6 The class MyBoolean has a single attribute named value of type boolean. Consider the following
    implementation of the equals method:
    public boolean equals(Object object) {
    boolean equals;
    if (object != null && this.getClass() == object.getClass()) {
    MyBoolean other = (MyBoolean) object;
    equals = this.value && other.value;
    }
    else {
    equals = false;
    }
    return equals;
    }
    Which of the following properties does the above equals method NOT satisfy? For all non-null references x, y and z,
    1. Ax.equals(y) returns true if and only if y.equals(x) returns true
    2. Bx.equals(null) returns false
    3. Cx.equals(x) returns true
    4. Dif x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) returns
      true.
  7. 7Which of the following is required for objects of a class to be considered immutable?
    1. Athe class should be declared as final.
    2. Bthe class should have no public mutators
    3. Cclass methods should not return references to class fields.
    4. Dall of the above.
    5. Esome of the above
  8. 8Suppose that an implementer creates a class that defines no constructors in the class body. Which one
    of the following statements is correct?
    1. Athe class must be a utility class
    2. Bthe class does not compile
    3. Cthe class compiles but is not useable.
    4. Dthe compiler adds a default (no-argument) constructor.
  9. 9Which statement is true for a static attribute (or field) of a class X?
    1. AThe class X has one copy of the attribute for every x object.
    2. BThe class X has the only copy of the attribute
    3. CEach X object has its own copy of the attribute.
    4. DOnly objects of classes that extend X have a copy of the attribute
  10. 10What is a class invariant?
    1. Aa condition that the method promises will be true immediately after the method finishes running
    2. Ba condition that the method must check at the beginning of the method
    3. Ca condition that the user (client) must ensure is true before calling the method
    4. Da condition that is always true immediately after a constructor or method finishes running

Information

Description
Quiz on All Mix EECS 2030, created by Muhammad Khan on 09/04/2020.
Language
English
Views
5
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?