CIS 120 MIDTERM 1 ALGORITHMS & THEIR LIMITATIONS COMPREHENSIVE EXAM 2026 Complete And Study material 13pages LEARNEXAMS

exam bundles
Loading...

Loading secure study material viewer...

Page 0 of 0

Document Text

1. Programming Concepts: Closures and Encapsulation (12 points) Multiple choice. For each question, mark answers. There may be zero or more than one. a. What value is computed for ans by the following OCaml program? type ’a ref = { mutable contents : ’a } let x = {contents = 4} let f : int -> int = let x = {contents = 2} in fun (y:int) -> y + x.contents ;; x.contents <- 1 let ans = f x.contents Q 2 Q 3 Q 4 Q 5 b. After running the following OCaml program, the closure named f will contain value bindings for which identifiers? let a : int = 50 let f : int -> int = let b = 60 in fun (c:int) -> a + b + c Q a Q b Q c Q f c. Consider the (simplified) Pixel class given by the Java code below: class Pixel { public int[] rgb = {0, 0, 0}; public Pixel(int r, int g, int b) { rgb[0] = r; rgb[1] = g; rgb[2] = b; } public int[] getComponents() { return rgb; } } To properly encapsulate the state of Pixel objects, the programmer should:


Download Study Material

Buy This Material

$35.00 One-time purchase
Buy Now
  • Full access to this material
  • Download anytime
  • No expiration

Study Material Information

Category: exam bundles
Description:

CIS 120 MIDTERM 1 ALGORITHMS & THEIR LIMITATIONS COMPREHENSIVE EXAM 2026 Complete And Study material 13pages LEARNEXAMS

Get this material $35.00