• Document: CC316: Object Oriented Programming
  • Size: 1.52 MB
  • Uploaded: 2018-12-08 18:14:55
  • Status: Successfully converted


Some snippets from your converted document:

CC316: Object Oriented Programming Lecture 14: Final Revision Dr. Manal Helal, Spring 2016. http://moodle.manalhelal.com 1 Q1) Object-oriented programming allows you to derive new classes from existing classes. This is called ________. 
 
 
 A) inheritance 
 B) encapsulation 
 C) generalization 
 D) abstraction 
 
 A1) A Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 2 Q2) Suppose you create a class Cylinder to be a subclass of Circle. Analyse the following code:
 
 class Cylinder extends Circle {
 double length;
 
 Cylinder(double radius) {
 Circle(radius);
 }
 }
 
 A) The program compiles fine, but you cannot create an instance of Cylinder because the constructor does not specify the length of the cylinder. 
 
 B) The program compiles fine, but it has a runtime error because of invoking the Circle class's constructor illegally. 
 
 C) The program has a compile error because you attempted to invoke the Circle class's constructor illegally.
 
 A2) C Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 3 Q3) Analyse the following code: (Choose all that apply.) public class Test extends A { public static void main(String[ ] args) { Test t = new Test(); t.print(); } A) The program does not compile because Test does not } have a default constructor Test(). class A { String s; B) The program would compile if a default constructor A() { } is added to class A explicitly. A(String s) { this.s = s; C) The program compiles, but it has a runtime error due to } the conflict on the method name print. public void print() { D) The program has an implicit default constructor Test(), System.out.println(s); but it cannot be compiled, because its super class does not } have a default constructor. The program would compile if } the constructor in the class A were removed.
 
 
 A3) B, D Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 4 Q4) Which of the statements regarding the super keyword is incorrect? A) You can use super to invoke a super class method. B) You cannot invoke a method in superclass's parent class. C) You can use super to invoke a super class constructor. D) You can use super.super.p to invoke a method in superclass's parent class. A4) D Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 5 Q5) Which of the following statements are true? (Choose all that apply.) A) To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass. B) A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden. C) A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated. D) Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them. E) It is a compilation error if two methods differ only in return type in the same class. A5) A, B, C, D, E Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 6 Q6) Analyze the following code: (Choose all that apply.) public class Test { public static void main(String[ ] args) { Object a1 = new A(); Object a2 = new Object(); System.out.println(a1); System.out.println(a2); A) The program cannot be compiled, because } System.out.println(a1) is wrong and it should be replac

Recently converted files (publicly available):