CSC 142 Exam #1 Spring 2020
1.) What kind of code does the Java compiler produce as its output?
2.) (T/F) It is possible to build a computer that does not use electricity at all.
3.) What number in hexadecimal is equivalent to the binary number 11100111?
4.) What is 01B2 in decimal? (show your work)
5.) Which of the following is the correct syntax to output a message?
a.) System.println(Hello, world!);
b.) Out.system.println"(Hello, world!)";
c.) System.println.out('Hello, world!');
d.) System.out.println("Hello, world!");
e.) System.println("Hello, world!");
6.) (T/F) Java Byte Code that has been compiled on a Windows 10 machine with an AMD Ryzen 9 3950X CPU should run just fine on an MacBook Pro with a Core i7 CPU.
7.) Which of the following are
valid
identifiers in java?
A.) Object#Count
B.) $money
C.) Late_Fee
D.) __$__
8.) (T/F) A Java
applet
is a stand-alone program that does not require a web browser.
9.) Matching:
A.) A group of 4 bits 1.) decimal
B.) Base-10 numbering system 2.) binary
C.) Base-16 numbering system 3.) nibble
D.) Base-2 numbering system 4.) hexadecimal
E.) A group of 8 bits 5.) byte
10.) (T/F) A
class
must be defined before you can call a method of that class.
11.) Suppose you have an application that manages the inventory of an auto dealership. A field is defined, “vehicleCount”, which contains the total number of vehicles in stock. Should this field be implemented as a
class
data value, or an
instance
data value?
12.) Draw an inheritance diagram for the classes: Animal, Cat, Dog, Cow.
13.) Which of these identifiers
obey
the naming
convention
for object names? (all of these are
legal
identifiers, I am asking about the object naming convention)
a.) Isthisokay
b.) goodName
c.) C3PO
d.) ThisIsReallyOkay
e.) areallygreatname
f.) anotherBadOne
14.) (T/F) A subclass may be defined to inherit from two superclasses.
15.) Draw the arrows for the state-of-memory diagram after the following code has executed. Put an X through any references that are no longer valid. :
String one = new String (“Moe”);
String two = new String (“Larry”);
String three = new String (“Curly”);
three = one;
one = two;
two = three;
one two three
String String String
16.) (Multiple Choice) In the statement ‘System.out.println();’ , what is ‘System’? (choose one answer only)
a.) An object
b.) An argument
c.) A method
d.) A class
17.) What is the value of the following expressions? Make sure to give a value of the appropriate type (such as including a .0 at the end of a
double
)
a.)
41 % 7 * 3 / 5 + 5 / 2 * 2.5
b.)
2 + 19 % 5 - (11 * (5 / 2))
18.) List the 6 primitive numerical data types in Java:
19.) What reserved word do we use to create an object in Java?
20.) The 3 types of comments in Java are: Single line comments, Multiple line comments, and __________________________.
21.) If Class A inherits from Class B, which is the superclass?
22.) What part in a computer contains the ALU?
23.) Find the 3 errors in the following code fragment:
class 1JavaTest{
public static void main (String] args){
myString String;
myString = new String(“Enter your Student ID: ”);
System.out.println(String);
}
}
24.) Write all the code for a class RadiationSample. There are only 2 fields in this class, a String that contains the date and time that the sample was logged, and a field that holds the number of counts per minute recorded, for that date and time. (the format of the date and time within the String does not matter, for this problem.)
The values for the date/time String, and the number of counts per minute are set in the constructor, so there are no “set” methods in the class. There are 2 “get” methods, one to return the String, and one to return the number of counts per minute.
25.) (Extra Credit-2 pts) Another numbering system used in computer science is
octal, or base-8.
What is the decimal (base 10) equivalent of 172 in octal? (show your work)