CMSC131 FINAL EXAM PREP QUESTIONS WITH
VERIFIED ANSWERS
The following declaration is possible:
public class Foo extends A implements B, C {
...
} - Answers - true
Where is a "current object" present? - Answers - Constructors and Instance methods
If you were taking an introductory programming course in the 1980's, which of these
languages is most likely to have been taught? - Answers - Pascal
Which of the following are considered "secondary memory devices." - Answers - USB
flash drive and hard drive
How many different values can be represented by 4 bits? - Answers - 16 (2^4)
What term describes the situation where two different variables refer to the same
object? - Answers - aliasing
How is your Java source code translated into machine code? - Answers - First a
compiler then an interpreter
What kinds of variables are stored on the call stack? - Answers - Local variables and
parameters
The following code fragment will compile:
int y = 5;
if(y < 10) {
int x = 17;
}
System.out.println(x); - Answers - False
What term describes 2^20 bytes of space? - Answers - megabyte
What kind of variables are used to represent the "state" of objects? - Answers - instance
variables
What advantages does primary memory have over secondary memory? - Answers -
Faster
Which of the following is the best definition for the term "byte"? - Answers - A sequence
of 8 bits
, What is the output of the following code fragment?
for(int x = 7; x < 11; x= x*2){
x-=3;
System.out.print(x)
} - Answers - 457
Which of the following will compile?
A. byte a = 17;
B. double c = 15F;
C. String e = 'x';
D. int b = 15L;
E. byte d = 130; - Answers - A, B
List the following operators in order of precedence (highest to lowest)
|| < += && == - Answers - < == && || +=
Write the binary representation of the number 50 - Answers - 110010
How many Dog objects are created by following code fragment?
Dog a = new Dog ("Spot"), c = new Dog("Alfie");
Dog b;
Dog d = a;
Dog f = new Dog(a); - Answers - 3
After the following code has been executed, how many objects have become garbage?
Dog a = new Dog( );
Dog b = new Dog( );
b = a;
a = new Dog( );
a = new Dog( ); - Answers - 2
After the following code has been executed, what is the value of the variable y?
int x =5, y = 10;
if(x++ == 5 || --y > 50){
y+=4;
} - Answers - 14
Assume that the following code has been executed.
String a = new String("bozo");
String b = a;
String c = new String(b);
Which of the following boolean expressions will evaluate as true?
a ==b
a.equals(c)
b==c - Answers - a==b
VERIFIED ANSWERS
The following declaration is possible:
public class Foo extends A implements B, C {
...
} - Answers - true
Where is a "current object" present? - Answers - Constructors and Instance methods
If you were taking an introductory programming course in the 1980's, which of these
languages is most likely to have been taught? - Answers - Pascal
Which of the following are considered "secondary memory devices." - Answers - USB
flash drive and hard drive
How many different values can be represented by 4 bits? - Answers - 16 (2^4)
What term describes the situation where two different variables refer to the same
object? - Answers - aliasing
How is your Java source code translated into machine code? - Answers - First a
compiler then an interpreter
What kinds of variables are stored on the call stack? - Answers - Local variables and
parameters
The following code fragment will compile:
int y = 5;
if(y < 10) {
int x = 17;
}
System.out.println(x); - Answers - False
What term describes 2^20 bytes of space? - Answers - megabyte
What kind of variables are used to represent the "state" of objects? - Answers - instance
variables
What advantages does primary memory have over secondary memory? - Answers -
Faster
Which of the following is the best definition for the term "byte"? - Answers - A sequence
of 8 bits
, What is the output of the following code fragment?
for(int x = 7; x < 11; x= x*2){
x-=3;
System.out.print(x)
} - Answers - 457
Which of the following will compile?
A. byte a = 17;
B. double c = 15F;
C. String e = 'x';
D. int b = 15L;
E. byte d = 130; - Answers - A, B
List the following operators in order of precedence (highest to lowest)
|| < += && == - Answers - < == && || +=
Write the binary representation of the number 50 - Answers - 110010
How many Dog objects are created by following code fragment?
Dog a = new Dog ("Spot"), c = new Dog("Alfie");
Dog b;
Dog d = a;
Dog f = new Dog(a); - Answers - 3
After the following code has been executed, how many objects have become garbage?
Dog a = new Dog( );
Dog b = new Dog( );
b = a;
a = new Dog( );
a = new Dog( ); - Answers - 2
After the following code has been executed, what is the value of the variable y?
int x =5, y = 10;
if(x++ == 5 || --y > 50){
y+=4;
} - Answers - 14
Assume that the following code has been executed.
String a = new String("bozo");
String b = a;
String c = new String(b);
Which of the following boolean expressions will evaluate as true?
a ==b
a.equals(c)
b==c - Answers - a==b