CSPP51036 Quiz 1 Chapters 1-4 10 minutes 1. public class T{ public static void main(String[] args){ String s = "hello"; foo(s); System.out.println(s); } static void foo(String s){ s = "goodbye"; } } What is printed? a) hello b) goodbye c) null d) none of above a. Object reference passed by value. ------------------------------- 2. public class T{ public static void main(String[] args){ int i = 10; foo(i); System.out.println(i); } static void foo(int i){ i = 1; } } What is printed? a) 10 b) 1 c) 0 d) none of above a) ints are passed by value ------------------------------------------ 3. public class T{ public static void main(String[] args){ Employee e = new Employee(40); foo(e); System.out.println(e); } static void foo(Employee e){ e.age = 30; } } class Employee{ public int age; Employee(int age){ this.age = age; } public String toString(){ return(new Integer(age).toString()); } } What is printed? a) something like Employee@1372a1a b) 0 c) 40 d) 30 d. Though object reference are pass by value, methods called upon them still manipulate same data. ----------------------------------- 4. Is it possible to write a compiler that compiles java into native code rather than bytecode? (Y or N) Y. ----------------------------------- 5. What is the "out" in System.out.println? (select all that apply) a) a method with no arguments b) a non-static member of the System class c) a static member of the System class d) An object c,d.. ----------------------------------- 6. Under what situations do you obtain a default constructor? a) When you define any class b) When the class has no other constructors c) When you define at least one constructor d) Only when you explicitly add one a or b (ambiguous wording). ----------------------------------- 7. Assuming a public constructor, a class with all static members can be instantiated. (T or F) T, though this is unusual. ----------------------------------- 8. In addition to the regular "public static void main(String[] args)", is it legal to define another method "public void main(String[] args)" in the same class? (Y or N) N. ----------------------------------- 9-10. Draw lines to match the keywords on the right with all possible entities they can modify on the left. outer class public method private class variable (denoted by blank) local variable final package static see quiz2 for a cleaner version of the same thing