Sample Questions for Quiz 1 CSCI 1902, Fall 2006 This is a set of sample questions for Quiz 1. It is intended to give you a sense of what type of questions to expect on the exam; in particular, it illustrates the different "levels of knowledge" of exam questions. There are several things this set of questions is *not*. (1) It is not a comprehensive list of the topics that may be covered. The best source for that is the lecture notes. (2) It is not a sample quiz: the set of questions below would take longer than 25 minutes to complete (3) It is not (syntactically speaking) an example of a successful "Quiz Question Proposal"; it contains more questions than necessary and no answers. Level 1: KNOWLEDGE What are two common types of loops in Java? (Specifically, what are the java keywords?) For each of the following pairs, state whether the pair has an IS-A relationship, a HAS-A relationship, or neither: boat ; sail boat ; vehicle car ; wildebeest wildebeest ; mammal Michael Jackson ; singer singer ; performer singer ; cheese cheese ; odor jail ; cells Level 2: COMPREHENSION & APPLICATION Suppose you're writing a class Book to hold information about books on your bookshelf. Write Java code to define three attributes you would use to represent Books; Write a constructor for Book to initialize your three attributes. Write the method "header" (not the body) for one behavior Books should exhibit. Define, in your own words, the following principles of object-oriented programming: class object attribute method inheritance encapsulation abstraction polymorphism ==================== [NOTE: WE MAY NOT COVER THIS IN TIME FOR THE QUIZ] Here are two Java classes. Add new methods (omit the method bodies) so that, between the two, there is: - One method which is overridden but not overloaded. - One method which is overloaded but not overridden. - One method which is both overridden and overloaded. - One method which is neither overridden nor overloaded. class Class1 { int a(int x) { } int b() { } } class Class2 extends Class1 { } ==================== Level 3: PROBLEM SOLVING For each of the principles of object-oriented programming listed above, give a new example that has not previously been discussed in class or any course activities. Write a method to compute the result of the following series: 1-1/2!+1/3!-1/4! Fill in the blanks in the code below. public double series(int n) { double sum=0; return sum; }