CMSC131 EXAM 1 QUESTIONS WITH VERIFIED
ANSWERS
A method that does not access any instance variables should be defined as: - Answers
- Static
When we call a method that has a String parameter, we pass to the method: - Answers
- The address of the String object
Which of the following is an alternative to the equals method to determine whether two
strings are
the same? - Answers - compareTo
Which one of the following correctly describes an immutable object? - Answers - An
object that, once created, cannot have its internal state changed.
What does the new operator return? - Answers - The address in the heap where the
object was created
A constructor method: - Answers - is called after the object has been created
A .class file is the result generated by the: - Answers - Java Compiler
The expression "cat".compareTo("dog") has: - Answers - A negative value.
The class Ceiling provides several methods and one of them can be called as follows:
Ceiling.compute(). What can we
say about the compute() method? - Answers - The compute() method is a static
method.
Which of the following expressions is equivalent to m *= 10 + p; ? - Answers - None of
the above.
When we append a string to another string (e.g., mes += "house"; where mes is a String
variable with the value "my"): - Answers - A new object is created that represents the
concatenation of mes and "house".
The Java compiler generates: - Answers - Bytecode.
How many different combinations of 0's and 1's can be represented with 4 bits? -
Answers - 16
Which of the following are variable names that will compile? - Answers - hot34, _$_145
, The decimal equivalent of the binary number 101 is: - Answers - 5
In the following code fragment, the casting of m to an integer will permanently change
the value of m to:
double m = 4.7;
System.out.println((int)m); - Answers - The value of m will not change
How many objects are present in the following code fragment?
int x = 7;
String result = ""; - Answers - 1
After the following code fragment is executed:
int x = Integer.parseInt("123 in"); - Answers - An error will take place when the code is
executed.
Which of the following is a high level programming language (Circle all that apply)? -
Answers - a. Java
The expression "cat".equals("dog") evaluates to: - Answers - false
Why do we use .equals for comparisons between String? What is == comparing? -
Answers -
Which of the following correctly generates an integer from 35-51 (inclusive, exclusive)? -
Answers -
What is the largest value that can be represented with 7 bits? - Answers - 256
What is 1110 0011 in base 10? - Answers -
Rachel is confused about the difference between declaring, initializing and instantiating.
Give an example of each below
with a brief description/explanation: - Answers - Declaring:
Initializing:
Instantiating:
What is 200 in base 2? - Answers -
How many objects are present in the following code fragment?
int x = 7;
String result = "";
StringBuffer resultBuff = new StringBuffer("Uhhh");
double y = 22; - Answers - 2
ANSWERS
A method that does not access any instance variables should be defined as: - Answers
- Static
When we call a method that has a String parameter, we pass to the method: - Answers
- The address of the String object
Which of the following is an alternative to the equals method to determine whether two
strings are
the same? - Answers - compareTo
Which one of the following correctly describes an immutable object? - Answers - An
object that, once created, cannot have its internal state changed.
What does the new operator return? - Answers - The address in the heap where the
object was created
A constructor method: - Answers - is called after the object has been created
A .class file is the result generated by the: - Answers - Java Compiler
The expression "cat".compareTo("dog") has: - Answers - A negative value.
The class Ceiling provides several methods and one of them can be called as follows:
Ceiling.compute(). What can we
say about the compute() method? - Answers - The compute() method is a static
method.
Which of the following expressions is equivalent to m *= 10 + p; ? - Answers - None of
the above.
When we append a string to another string (e.g., mes += "house"; where mes is a String
variable with the value "my"): - Answers - A new object is created that represents the
concatenation of mes and "house".
The Java compiler generates: - Answers - Bytecode.
How many different combinations of 0's and 1's can be represented with 4 bits? -
Answers - 16
Which of the following are variable names that will compile? - Answers - hot34, _$_145
, The decimal equivalent of the binary number 101 is: - Answers - 5
In the following code fragment, the casting of m to an integer will permanently change
the value of m to:
double m = 4.7;
System.out.println((int)m); - Answers - The value of m will not change
How many objects are present in the following code fragment?
int x = 7;
String result = ""; - Answers - 1
After the following code fragment is executed:
int x = Integer.parseInt("123 in"); - Answers - An error will take place when the code is
executed.
Which of the following is a high level programming language (Circle all that apply)? -
Answers - a. Java
The expression "cat".equals("dog") evaluates to: - Answers - false
Why do we use .equals for comparisons between String? What is == comparing? -
Answers -
Which of the following correctly generates an integer from 35-51 (inclusive, exclusive)? -
Answers -
What is the largest value that can be represented with 7 bits? - Answers - 256
What is 1110 0011 in base 10? - Answers -
Rachel is confused about the difference between declaring, initializing and instantiating.
Give an example of each below
with a brief description/explanation: - Answers - Declaring:
Initializing:
Instantiating:
What is 200 in base 2? - Answers -
How many objects are present in the following code fragment?
int x = 7;
String result = "";
StringBuffer resultBuff = new StringBuffer("Uhhh");
double y = 22; - Answers - 2