COMP 101 Study Guide - Midterm Guide: Object-Oriented Programming, Bytecode, Machine Code

176 views12 pages
19 Jun 2018
School
Department
Course
Professor
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
find more resources at oneclass.com
find more resources at oneclass.com
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
find more resources at oneclass.com
find more resources at oneclass.com
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
12. What is the range of the random number rgenerated by the code below?
int r = (int)(Math.floor(Math.random() * 8)) + 2;
(a) 3 <= r <= 10
(b) 3 <= r <= 9
(c) 2 <= r <= 10
(d) 2 <= r <= 9 ******
13. If a local variable of a method shop() belonging to a class called Walmart has the same name as
a data member of Walmart, which value is used when shop() is executing?
(a) the local variable’s ******
(b) the class variable’s
(c) the data member’s
(d) None of the above since this would cause a compiler error.
14. What will be printed by the code fragment below?
double height = 5.5;
if(height-- >= 5.0)
System.out.print("tall ");
if(--height >= 4.0)
System.out.print("average ");
if(height-- >= 3.0)
System.out.print("short ");
else
System.out.print("very short ");
(a) short
(b) average short
(c) tall short ******
(d) tall
15. Translate this statement into Java:
If the value of temperature is in between 20.0 and 40.0, print “very cold”.
(a) if(!(temperature < 20.0 || temperature > 40.0)) ******
System.out.println("very cold");
(b) if(20.0 <= temperature <= 40.0)
System.out.println("very cold");
(c) if(temperature >= 20.0 || temperature <= 40.0)
System.out.println("very cold");
(d) if(temperature >= 20.0 | temperature <= 40.0)
System.out.println("very cold");
3
find more resources at oneclass.com
find more resources at oneclass.com
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

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

Related Questions