Question
Question 1: The process method in the excerpt below must be non-static. MyType obj1 = new MyType(); obj1.process(somefile.txt); Question 2: The send method in the
Question 1:
The process method in the excerpt below must be non-static.
MyType obj1 = new MyType(); obj1.process("somefile.txt");
Question 2:
The send method in the excerpt below must be static.
MyType obj1 = new MyType();
MyType.send(obj1);
Question 3:
The code excerpt below declares an instance variable as final without immediately assigning it a value (the code attempts to set its value in the constructor). This is valid.
public class ConnectionManager {
private final int maxConnections;
public ConnectionManager(int maxConnections) {
this.maxConnections = maxConnections;
}
// ...
}
Question 4:
What is the value of x after the following statement is executed?
double x = Math.floor(Math.abs(Math.ceil(3.1) + Math.floor(12.99) - 20.5));
Note:
- If the answer is a real number (a rational number that is not an integer... the sort of stuff we'd normally store in a float or double) it should be rounded to display only 1 digit to the right of the decimal. That is, an answer of 7.314 should be entered of 7.3 and an answer of 7.553 should be entered as 7.6.
Question 5:
You ______ an item onto a stack to add it, and _____ an item off of a stack to remove it.
Question 6:
A _______ is a last-in, first-out (LIFO) data structure.
Question 7:
Select those code excerpts below that are valid.
public static void main(String args[]) { promo(21.7); }
static void promo(int param) { // ... } | ||
public static void main(String args[]) { float discount = 10.5f; promo(discount); }
static void promo(double param) { // ... } | ||
public static void main(String args[]) { promo(10.5); }
static void promo(float param) { // ... } | ||
public static void main(String args[]) { promo(10); }
static void promo(float param) { // ... } | ||
public static void main(String args[]) { promo((int) 21.7); }
static void promo(int param) { // ... } |
Question 8:
The nextInt method in the Random class produces truly random (i.e. nondeterministic) values such that every value in the range (-2,147,483,648 to +2,147,483,647 inclusive) has an equal chance (probability) of being chosen each time nextInt is called.
True or False?
Question 9:
Select the true statements below
enumerations are a special kind of class | ||
enumerations are introduced (declared) using the keyword boundedtype | ||
The names of all enumeration constants must use only uppercase letters | ||
The body of an enumeration contains a comma-separated list of enumeration constants, each representing a unique value | ||
Use of enumeration constants (like Mood.HAPPY, Mood.SAD, and Mood.HEAVILYMEDICATED) in place of literal values (such as 0, 1 and 2) may make code easier to read and maintain |
Question 10:
The following code excerpt is valid demonstration of method overloading:
static int downcast(double arg) {
return (int) arg;
}
static float downcast(double arg) {
return (float) arg;
}
True or False?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started