COMP 202 Study Guide - Final Guide: Cheat Sheet, Immutable Object, The Possession

85 views11 pages
First Name:Last Name:
McGill ID:Section:
Faculty of Science
COMP-202A - Foundations of Computing (Fall 2016) - All Sections
Final Examination
December 12th, 2016 Examiners: Melanie Lyman-Abramovitch [Section 1 (MWF 8:35-9:25)]
18:00 - 21:00 Kaleem Siddiqi [Section 2 TR (8:35-9:55)]
Dan Pomerantz [Section 3 MWF (16:35-17:25)]
Instructions:
DO NOT TURN THIS PAGE UNTIL INSTRUCTED
This is a closed book examination; only a legal-sized (8.5” by 14”) crib sheet is permitted. This crib sheet can
be single or double-sided; it can be handwritten or typed. Non-electronic translation dictionaries are permitted,
but instructors and invigilators reserve the right to inspect them at any time during the examination.
Besides the above, only writing implements (pens, pencils, erasers, pencil sharpeners, etc.) are allowed. The
possession of any other tools or devices is prohibited.
Answer all questions on the answer sheet.
This examination has 11 pages including this cover page, and is printed on both sides of the paper. On page
11, you will find information about useful classes and methods.You may detach the Appendix (page 11
onwards) from the examination if you wish.
Scoring
The exam will be scored as follows:
1. Questions 1 to 10 are worth 1 point each
2. Questions 11 to 32 are worth 2 points each
3. The Long Answer Question is worth 40 points
4. Total: 92 points
Version-0
Unlock document

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

Already have an account? Log in
COMP-202A - Fall 2016 - Final Examination - Version-0 Page 2
True/False Section (1 point each)
For all of the following, write either true or false. You must write the whole word.
1. It is possible to call a non-static method on the class in which it was written.
2. A private method can only be used directly inside the class in which it was written.
3. In Java, there are some types of exceptions which the compiler requires you to handle. The only way to deal
with these compiler errors is to use a try-catch block.
4. The following snippet of code prints Same.
int[] a = {1,2};
int[] b = new int[2];
b[0] = 1;
b[1] = 2;
if (a == b) {
System.out.println("Same");
}
else {
System.out.println("Different");
}
5. In Java, you can create an ArrayList of a primitive type such as ArrayList<int>.
6. The following prints 4 5
public static void main(String[] args) {
int x = 4;
int y = 5;
swap(x,y);
System.out.println(x + " " + y);
}
public static int swap(int x, int y) {
int temp = y;
y = x;
x = temp;
return x;
}
7. The following prints 4 5
public static void main(String[] args){
int[] a = {4,5,6};
swap(a,0,1);
System.out.println(a[0] + " " + a[1]);
}
public static void swap(int[] a, int x, int y){
int t = a[x];
a[x] = a[y];
a[y] = t;
}
Unlock document

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

Already have an account? Log in
COMP-202A - Fall 2016 - Final Examination - Version-0 Page 3
8. The following prints 4 5
public static void main(String[] args){
int[] a = {4,5,6};
swap(a,0,1);
System.out.println(a[0] + " " + a[1]);
}
public static void swap(int[] a, int x, int y){
a = new int[3];
int t = a[x];
a[x] = a[y];
a[y] = t;
}
9. The following class describes an immutable object. Recall that an object is immutable if it contents cannot be
changed after it has been created.
public class MyValue{
private int value;
public MyValue(int x){
this.value = x;
}
public void print(){
System.out.println(this.value);
}
}
10. The following example of a Dog class will compile without error.
public class Dog {
public Dog(String name, int age){
System.out.println("hi!");
}
public Dog2(String color) {
System.out.println(color);
}
public static void main(String[] args){
Dog dog1 = new Dog("Jack",5);
Dog dog2 = new Dog2("Jill");
}
}
Unlock document

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

Already have an account? Log in
hwpark22 and 40159 others unlocked
COMP 202 Full Course Notes
100
COMP 202 Full Course Notes
Verified Note
100 documents

Document Summary

Comp-202a - foundations of computing (fall 2016) - all sections. Instructions: do not turn this page until instructed, this is a closed book examination; only a legal-sized (8. 5 by 14 ) crib sheet is permitted. This crib sheet can be single or double-sided; it can be handwritten or typed. Non-electronic translation dictionaries are permitted, but instructors and invigilators reserve the right to inspect them at any time during the examination: besides the above, only writing implements (pens, pencils, erasers, pencil sharpeners, etc. ) are allowed. The possession of any other tools or devices is prohibited: answer all questions on the answer sheet, this examination has 11 pages including this cover page, and is printed on both sides of the paper. 11, you will nd information about useful classes and methods. You may detach the appendix (page 11 onwards) from the examination if you wish.

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