Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Type Checking Assignment in CS415: Multiple Inheritance and Array Assignments, Assignments of Programming Languages

Information about a written assignment for cs415 students, focusing on type checking concepts such as multiple inheritance and array assignments in c++ and java. The assignment asks students to explain why multiple inheritance changes the way least upper bounds are defined, implement lub for multiple inheritance, and write java code that triggers runtime checks for unsound typing rules in array assignments.

Typology: Assignments

Pre 2010

Uploaded on 03/10/2009

koofers-user-vsx
koofers-user-vsx 🇺🇸

10 documents

1 / 3

Toggle sidebar

Related documents


Partial preview of the text

Download Type Checking Assignment in CS415: Multiple Inheritance and Array Assignments and more Assignments Programming Languages in PDF only on Docsity! CS415 — Written Assignment 5 March 21, 2008 This assignment asks you to prepare written answers to questions on type checking. Each of the questions has a short answer. You may discuss this assignment with other students and work on the problems together. However, your write-up should be your own individual work. Please print your name and email address on your homework! We need this information so that we can give you credit for the assignment and so that we can return it to you. 1. C++, unlike COOL, supports multiple inheritance. For example, the following class hierarchy is legal in C++: A / \ B C \ / D Allowing multiple inheritance changes the way we define and use the least upper bound (lub) function on types. (a) Explain, using at least one example, why it is necessary to change lub. (b) Describe how you might implement lub for multiple inheritance. Be brief. 2. The Java programming language includes arrays. The Java language specifica- tion states that if s is an array of elements of class S, and t is an array of elements of class T , then the assignment s = t is allowed as long as T is a subclass of S. This typing rule for array assignments turns out to be unsound. Java works around this by inserting runtime checks to throw an exception if arrays are used unsafely. 1 Consider the following Java program, which type checks according to the pre- ceeding rule: Listing 1: totally innocuous Java code class Mammal { String name; } class Dog extends Mammal { void beginBarking() { ... } } class Main { public static void main(String argv[]) { Dog x[] = new Dog[5]; Mammal y[] = x; // Insert your code here } } Add code to the main method so that the resulting program is a valid Java program (i.e., it compiles), but running that program triggers one of the afore- mentioned runtime checks. Include a brief explanation of how your program exhibits the problem. 3. The following typing judgments have one or more flaws. For each judgment, list the flaws and explain how they affect the judgment. (a) O ` e0 : T O ` T ≤ T0 O ` e1 : T1 O[x/T0] ` let x : T0 ← e0 in e1 : T1 (let− init) (b) O(id) = T0 O ` e1 : T1 T0 ≤ T1 O ` id← e1 : T1 (assign) (c) T ≤ C ` SELF TYPEC ≤ T (self − type) 2
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved