Answers and Review for Multiple Choice Practice on Inheritance
Image From Wikipedia.
βSTOP!β Before you look at the answers make sure you gave this practice quiz a try so you can assess your understanding of the concepts covered in unit 9. Click here for the practice questions:
AP CSA Unit 9 Multiple Choice Questions.Facts about the test: The AP Computer Science A exam has 40 multiple choice questions and you will be given 90 minutes to complete the section. That means it should take you around 23 minutes to complete 10 questions.
*The following questions were not written by CollegeBoard and although they cover information outlined in the
AP Computer Science A Course and Exam Description the formatting on the exam may be different.
A. public class SubClass extends SuperClass {}
B. public class SubClass {}
C. public class SubClass parent SuperClass {}
D. public class SubClass super SuperClass {}
Answer:Β proper syntax
A. this
B. extends
C. requires
D. ββsuper
Answer:Β definition as parent class is also known as the superclass, therefore the super keyword is used to call objects from the parent class
π Study AP CSA, Unit 9.4:Β Super Keyword
A.Β
B.Β
C.Β
D.Β
Answer:Β Definiton: Overloading a method requires that the method has the same name, same return type, but has to have different parameters, whether that would be the number of parameters, the types of the parameters, or the order of the parameters
π Study AP CSA, Unit 9.3: Overriding Methods
A.Β
B.Β
C.Β
D.Β
Answer:Β Definiton: Definiton: Overriding a method requires that the method has the same name, same return type, and same parameters. The only difference is whatever is in the method can be different from the method in the parent class
π Study AP CSA, Unit 9.3:Β
Overriding Methods
A.Β
B.Β
C.Β
D.Β
Answer:Β Width is a private variable in the parent class, which is not visible to the subclass, so using the public setWidth method would work instead.Β
A.Β
B.Β
C.Β
D.Β
Answer:Β
Polymorphism definition. Since Three is a subclass of One and Two, object1 and object2 are objects of One and Two. However, an object of One or Two or Three (being the superclasses of Four) is not always an object of Four.Β
π Study AP CSA, Unit 9.6:Β Polymorphism
A. OneTwo
B. Three
C. OneTwoFourThree
D. OneTwoThreeFour
Answer:Β
Since the object created is a Two object, this means that the method called will be the printMethod1 in the Two class. So, printMethod1 in the Two class is called, which calls the superclass method printMethod1 in One. That prints out βOneβ, and then calls printMethod2 in the Two class, which then calls the superclass method printMethod2 in One. That prints out βTwoβ, and then goes back to the printMethod2 in Two. That prints out βFourβ, and then goes back to the printMethod1 in the Two class, which prints out βThreeβ, ending the code.Β
A. I
B. II
C. I, II
D. I, II, III
Answer:Β
Basic knowledge, the toString() method is often overriden to explain what the specific object is and does in text form. The equals() method compares two objects to see if they are the same, which is often overriden as for different objects, sometimes the features within it are what should determine equality, and it will differ. The toFinalize() method doesn't exist in the Object class.
π Study AP CSA, Unit 9.3:Β Overriding Methods
A. This variable/method belongs to the class and is not specific for each instance created of that class.
B. This variable/method belongs to an object created of the class and is specific for each instance created of that class.
C. This variable/method belongs to the class and is specific for each instance created of that class.
D. This variable/method belongs to an object created of the class and is not specific for each instance created of that class.
π Study AP CSA, Unit 9.6:Β Polymorphism
A. 25.25
B. 30.75
C. compiler error due to a CottonPillow object created in place of a Pillow object
D. compiler error due to CottonPillow not having a getActualCost() method
Answer:Β
An object can be created as its subclass. Since CottonPillow is a subclass of the superclass Pillow, it inherits its methods. Despite CottonPillow not having its own getActualCost() method, the call to the getActualCost() method calls the getActualCost() method in Pillow. However, this.getCost() will call the getCost() method in CottonPillow because the object is a CottonPillow object, and not a Pillow object.Β
π¦ Jump to AP CSA Unit 10 Multiple Choice Questions
π€ Connect with other students studying AP CSA with
Hours