CMSC 131 EXAM 2 QUESTIONS WITH VERIFIED ANSWERS
Correct 31
Incorrect 00
Your answers
1 of 31
Definition
s = c == 'y' ? "Yes" : "No";
Give this one a try later!
public class Values {
private String distance;
private double cost;
private boolean completed;
public static void main(String[] args) {
Values values = new Values();
System.out.println(values.distance);
System.out.println(values.cost);
System.out.println(values.completed);
}
}
, When we call a.doSomething(b) which value does the special value this (present
inside of the doSomething method) have?
a. It has the same value a has
b. It has the same value b has
c. It has the value null
d. None of the above.
We can call a non-static method of a class (circle all that apply):
a. Only if an object of the class has already been created.
b. From a static method of the class.
c. By using the class name (e.g., ClassName.method)
d. None of the above.
Assuming variable c is a character type variable and s is a string type variable,
rewrite the following code using a single statement and the ternary operator
so s is assigned the correct value.
if (c == 'y') {
s = "Yes";
} else {
s = "No";
}
Don't know?
2 of 31
Definition
b
Give this one a try later!
, Which of the following actually creates an object?
a. Destructor
b. Constructor
c. new operator
d. None of the above.
Circle all the areas where an object can be found.
a. Stack
b. Heap
c. Only in the first method that has been called.
d. None of the above
Would the following class compile? Yes / No
public class Misc2 {
public static void main(String[] args) {
String m;
System.out.println(m);
}
}
Which of the following actually creates an object?
a. new
b. constructor
c. private
d. None of the above.
Don't know?
Correct 31
Incorrect 00
Your answers
1 of 31
Definition
s = c == 'y' ? "Yes" : "No";
Give this one a try later!
public class Values {
private String distance;
private double cost;
private boolean completed;
public static void main(String[] args) {
Values values = new Values();
System.out.println(values.distance);
System.out.println(values.cost);
System.out.println(values.completed);
}
}
, When we call a.doSomething(b) which value does the special value this (present
inside of the doSomething method) have?
a. It has the same value a has
b. It has the same value b has
c. It has the value null
d. None of the above.
We can call a non-static method of a class (circle all that apply):
a. Only if an object of the class has already been created.
b. From a static method of the class.
c. By using the class name (e.g., ClassName.method)
d. None of the above.
Assuming variable c is a character type variable and s is a string type variable,
rewrite the following code using a single statement and the ternary operator
so s is assigned the correct value.
if (c == 'y') {
s = "Yes";
} else {
s = "No";
}
Don't know?
2 of 31
Definition
b
Give this one a try later!
, Which of the following actually creates an object?
a. Destructor
b. Constructor
c. new operator
d. None of the above.
Circle all the areas where an object can be found.
a. Stack
b. Heap
c. Only in the first method that has been called.
d. None of the above
Would the following class compile? Yes / No
public class Misc2 {
public static void main(String[] args) {
String m;
System.out.println(m);
}
}
Which of the following actually creates an object?
a. new
b. constructor
c. private
d. None of the above.
Don't know?