Chapter 5 Computer Science Questions

445 Words2 Pages
Chapter 5 End-Of-Chapter questions Multiple Choice 1. a 2. c 3. a 4. b 5. e 6. c 7. e 8. d 9. e 10. d True/False 1. t 2. t 3. f 4. f 5. t 6. t 7. f 8. t 9. t 10. t Short Answer 5.1 What is output by the following code? String s1 = “hello “; String s2 = s1; s2 = s2 + “there “; System.out.println(s1); System.out.println(s2); hello hello there 5.2 Discuss how Java passes parameters to a method. Is this technique the same for primitive types and objects? Explain. Java passes all parameters by value which means that the current value of the actual parameter is copied into the formal parameter in the method header. * 5.3 Explain why a static method cannot refer to an instance variable. A static method is invoked through a class rather than through an object of the class. No object of the class needs to be instantiated in order to invoke a static method 5.4 Can a class implement two interfaces that each contain the same method signature? Explain. Yes, The class which implements an interface provides method implementations for each of the abstract methods defined in the interface. 5.5 Create an interface called Visible that includes two methods: makeVisible and makeInvisible. Both methods should take no parameters and should return a boolean result. Describe how a class might implement this interface. public interface Visible { public boolean makeVisible (); public boolean makeInvisible (); } A class implementing Visible would begin with public class Icon implements Visible * 5.6 Create an interface called VCR with methods that represent what a video cassette recorder does (play, stop, etc.). Define the method signatures any way you want. Describe how a class might implement this interface. public interface VCR {
Open Document