2008fall_final - 1 (30) 2 (20) 3 (20) 4 (30) 5 (25) 6 (25)...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
- 1 - 1 (30) 2 (20) 3 (20) 4 (30) 5 (25) 6 (25) Total (150) CS101 Introduction to Programming Final Exam (Fall 2008) Section Student ID Name 1 . Answer each question according to the instruction. (30 points) 1-1 . When the program reaches point X , which of the six logical expressions will be true? ( , , , ) (3 points) public class C { private int val=10; public int getVal() { return val; } public void test() { C a = new C(); C b = new C(); C c = b; int x = 10; double y = 10.0; // point X } } a == x a == b b == c x == y x == a.val x == a.getVal()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
- 2 - 1-2 . What is the range of the value of 'a' that will print "output2" on the console? ( ) (3 points) if (a > 3) System.out.println("output1"); else if (a > 7) System.out.println("output2"); else System.out.println("output3"); a < 0 a < 3 3 a 7 a > 7 none 1-3 . Which of the following statement is true? ( ) (3 points) If a class does not have any explicitly defined constructor, we cannot instantiate any object of the class. A constructor is a method that is called when an object of the class is created. If a class contains two methods whose signature differ only in return types, then those two methods are overloaded methods. We can declare the return type of a constructor to be void . Within one class, you can have two (or more) definitions of a single method name. This is called method overriding. 1-4 . What is the result of the following program? ( ) (3 points) public class Array { public static void main(String[] args) { int[] a = { 2, 3, 5, 7, 11 }; int[] b = change(a); System.out.println(a[0] + "," + b[4]); } public static int[] change(int[] p) { int[] newInt = p; for(int i = 0; i < p.length - 1; i++) { p[i]++; newInt[i]++; } return newInt; } } 2,11 3,12 4,11 4,12 3,11
Background image of page 2
- 3 - 1-5 . What will be the outcome of the program below? ( ) (3 points) import java.util.*; public class TestStringTokenizer { public static void main(String[] args) { StringTokenizer st = new StringTokenizer(“1,2,3,4,5,6,7,8”, “,”); int sum = 0; for(int i=0; i<st.countTokens(); i++) { sum += Integer.parseInt(st.nextToken()); } System.out.println(sum); } } 10 15 21 28 36 1-6 . Given the following three classes, which of the five statements is correct? ( ) (3 points) // Person.java public abstract class Person { abstract public void abc(); } // Student.java public class Student extends Person { public void abc() { System.out.println(“Student”); } } // Graduate.java public abstract class Graduate extends Student { abstract public void def(); } Person p = new Person(); Student s = new Graduate(); Graduate g = new Student(); Person p = new Student(); Graduate g = new Graduate();
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
- 4 - 1-7 . Fill in the three blanks, marked (a), (b), and (c) each with one of the given four expressions. (3 points) public class Generic (a) { private T data; public void setData(T newValue) {
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

2008fall_final - 1 (30) 2 (20) 3 (20) 4 (30) 5 (25) 6 (25)...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online