test2 KEY - COP 3330 Exam #2 Summer 2011 Wednesday July 20,...

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

View Full Document Right Arrow Icon
1 (Question 1 – 20 points (2pts/answer) – True/False Questions: Various Topics) Circle the correct answer. a. Abstract methods cannot be static. TRUE FALSE b. A subclass can be abstract even if its superclass is concrete. TRUE FALSE c. An interface can extend any class as well as extend any interface. TRUE FALSE d. It is possible for more than one subclass to extend the same superclass. TRUE FALSE e. Any class that contains an abstract method must be declared abstract. TRUE FALSE f. A subclass object is a specialized superclass object and therefore the super class object is always both a subclass and superclass type. TRUE FALSE g. In Java a class can extend one class and implement many interfaces. TRUE FALSE h. To explicitly invoke the superclass constructor on the object under construction, the keyword super must be used. TRUE FALSE i. An abstract class cannot be instantiated using the new operator and therefore you cannot provide an implementation of a constructor in an abstract class. TRUE FALSE j. Polymorphism occurs when a code expression can invoke different methods depending on the types of objects using the code. TRUE FALSE COP 3330 – Exam #2 – Summer 2011 Wednesday July 20, 2011 100 points total PRINT YOUR NAME CLEARLY Name: ID: KEY
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 (Question 2 – 12 points (2pts/answer) – Tracing Code Execution) What will be the output of the following Java program? Put your answers in the spaces provided. class A { public int x=1; public int y=5; public A() { y=6; } public A(int a) { x=a; } public A(int a, int b) { x=a; y=b; } }//end class A class B extends A { public B() {} public B(int a) { super(a); } public B(int a, int b) { this(a,b,2); } public B(int a, int b, int c) { x=a+b+c; y=y+c; } public B(int a, int b, int c, int d) { super(a,b); y=c+d; } public B(B a, int b) { } }//end class B public class TestQuestion2 { public static void main(String[] args) { B b1 = new B(); System.out.println("b1.x: " + b1.x + " b1.y: " + b1.y); B b2 = new B(2); System.out.println("b2.x: " + b2.x + " b2.y: " + b2.y); B b3 = new B(2,4); System.out.println("b3.x: " + b3.x + " b3.y: " + b3.y); B b4 = new B(1,1,1); System.out.println("b4.x: " + b4.x + " b4.y: " + b4.y); B b5 = new B(2,2,2,2); System.out.println("b5.x: " + b5.x + " b5.y: " + b5.y); B b6 = new B(new B(), 3); System.out.println("b6.x: " + b6.x + " b6.y: " + b6.y); } //end main method }//end class TestQuestion2 ANSWERS: 1 b1.x: 6 b1.y: 2 b2.x: 5 b2.y: 8 b3.x: 8 b3.y: 3 b4.x: 7 b4.y: 2 b5.x: 4 b5.y: 1 b6.x: 6 b6.y:
Background image of page 2
3 Trace of execution for TestQuestion2 B b1 = new B( ) Invoking default constructor in B requires implicitly invoking the default constructor in A first. In A the members are x = 1 and y = 5 but the default constructor modifies the value of y to 6. Thus b1.x = 1 and b1.y = 6. B b2 = new B(2)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/21/2011 for the course COP 3330 taught by Professor Staff during the Fall '08 term at University of Central Florida.

Page1 / 11

test2 KEY - COP 3330 Exam #2 Summer 2011 Wednesday July 20,...

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

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