CS 18000 Study Guide - Midterm Guide: Machine Code, Class Variable, Bytecode

183 views12 pages
CS 180 Spring 2009 Exam I
There are 20 multiple choice questions. Each one is worth 2 points. There are 3 programming
questions worth a total of 60 points.
Answer the multiple choice questions on the bubble sheet given and the programming ques-
tions on the exam booklet.
Fill in the Instructor, Course, Signature, Test, and Date blanks. For “Instructor” put your
Recitation Instructor’s last name. For “Course” put CS 180. For “Test” put Exam 1.
Fill in the bubbles that correspond to your name, section and Student ID in the bubble sheet.
For your section number, use the section number for your lab and project turn in. Consult the
following list:
0101 Friday 07:30 LWSN 1106 J. C. Chin
0201 Friday 08:30 LWSN 1106 Yinian Qi
0301 Friday 09:30 HAAS G066 Cheng Wang
0401 Friday 11:30 LWSN 1106 Salman Pervez
0501 Friday 01:30 HAAS G066 Nwokedi Idika
For your student ID, use the 10 digit ID number on your student ID card. DO NOT USE YOUR
SOCIAL SECURITY NUMBER!
Exams without names will be graded as zero. Only the answers on the bubble sheet will be
counted. The questions will be discarded.
Recitation Section Number
Recitation TAs Name
Student Last Name
Student First Name
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 12 pages and 3 million more documents.

Already have an account? Log in
Part I. Multiple Choice Questions (2 points each):
1. Which of the following is NOT a key component of object oriented programming?
(a) Inheritance
(b) Encapsulation
(c) Polymorphism
(d) Parallelism ******
2. Which of these is TRUE of the relationship between objects and classes?
(a) A class is an instance of an object.
(b) An object is the ancestor of its subclass.
(c) An object is an instance of a class. ******
(d) An object is the descendant of its superclass.
3. The Java compiler translates source code into
(a) machine code.
(b) Assembly code.
(c) Byte code. ******
(d) JVM code.
4. Which of the following is NOT a valid ‘type’ in Java?
(a) void
(b) int
(c) Integer
(d) static ******
5. Which of the following statements is NOT correct?
(a) We can use a new operator on String to create a "String" object.
(b) We can use the new operator on int to create an "int" object. ******
(c) Variables of type "int" can be assigned a value just after being declared.
(d) Variables of type "String" can be assigned a value just after being declared.
6. Which of the following statements can provide the output "180"?
(a) String str = "CS180";
System.out.print(str.substring(2, 4));
(b) String str = "CS180";
System.out.print(str.substring(3, 5));
(c) String str = "P";
System.out.print(str.length() + "80"); ******
(d) String str = "P";
System.out.print(str.length() + 80);
1
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 12 pages and 3 million more documents.

Already have an account? Log in
7. What is the output of the following code if the input string is "CS 180"?
Scanner scanner = new Scanner();
String str;
str = scanner.next();
System.out.print(str);
(a) CS180
(b) CS
(c) CS 180
(d) The above code fragment does not compile. ******
8. Which of the following is NOT true?
(a) Both float and double represent real numbers.
(b) long can present a larger range of values than double. ******
(c) The size of long and double is the same.
(d) char is not a numeric data type.
9. Which of the following is TRUE about the piece of JAVA code below if we judge the statements
independently?
final double PI;
int radius = Integer.parseInt("3.5");
double area = Math.PI * Math.pow(radius, 2);
(a) The third statement computes the area of a circle whose radius is in variable radius. ******
(b) The first statement correctly declares the constant PI.
(c) The second statement correctly obtains the radius from the given string.
(d) The third statement incorrectly uses Math.pow.
10. What is the value of ywhen the code below is executed?
int x = 4;
int y = (int)Math.ceil(x % 5 + x / 5.0);
(a) 1
(b) 6
(c) 5 ******
(d) 4
11. Which of the following statements is TRUE?
(a) The Java compiler always adds a default constructor to a user defined class.
(b) Each instantiated object will have its own copy of a class variable.
(c) When an object is passed to a method, a copy of each of the object’s data members are created
and passed to the method.
(d) A class can have multiple constructors. ******
2
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 12 pages and 3 million more documents.

Already have an account? Log in

Document Summary

There are 3 programming questions worth a total of 60 points. Answer the multiple choice questions on the bubble sheet given and the programming ques- tions on the exam booklet. Fill in the instructor, course, signature, test, and date blanks. Fill in the bubbles that correspond to your name, section and student id in the bubble sheet. For your section number, use the section number for your lab and project turn in. 0101 friday 07:30 lwsn 1106 j. c. chin. For your student id, use the 10 digit id number on your student id card. Exams without names will be graded as zero. Only the answers on the bubble sheet will be counted. System. out. print(str. length() + "80"); ****** (d) string str = "p"; System. out. print("very short "); (a) short (b) average short (c) tall short ****** (d) tall: translate this statement into java:

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents