# CSC 123/252 Scary Test # A scary test will make you study really hard for the real test. # Answer each question carefully. The test will be "graded". #1. Explain the difference between the C# functions f and g below: Func f() { return (d0) => { int y=0; y+=d0; return y; }; } Func g() { int y=0; return (d0) => { y+=d0; return y; }; } #Determine the output of var f1 = f(); var g1 = g(); Console.WriteLine(f1(1)+f1(1)); Console.WriteLine(g1(1)+g1(1)); 1b. which of the above functions can be written in C? Explain. 2. Someone has invented a new language called C** that's claimed to be the best ever. The syntax certainly looks familiar: int x = 1; // declares and initializes global variable int f(int y) { return y+1; } // define function with argument y void MAIN() // MAIN must be in all capitals (ingenious!) { int x = 2; // declares "local" variable inside main stdout << f(x) << endl; // fantastic new way to print! // this will print 3 in C** } But you didn't find any documentation on whether this language uses static or dynamic {\bf scoping.} Devise an experiment (write a program in C**) to find out. That is, write one program that will behave differently depending on the scoping rule used. Be clear as to how to interpret the result of your experiment. 3. Explain why or why won't the following JAVA generic class compiles class A { static T x; } // will this compile? 4. Explain why object[] A = new string[4]; should not compile (regardless of whether it does) 5. Determine the output of the following C# program class A {} class B : A {} public class goodquestion { public int f(A x) { return 1; } public int f(B x) { return 2; } public static void Main() { A n = new B(); goodquestion gq = new goodquestion(); System.Console.WriteLine( gq.f(n) ); }//main }