CSC_241_QUIZ_01_SP_20

docx

School

University of Wisconsin, Madison *

*We aren’t endorsed by this school

Course

740

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

3

Uploaded by MegaFlagGoldfinch46

Report
CSC 241 Quiz 1 SP 20 (Chapter 1 material) _____ / 50 points Student name: ____ Lexi Siegel _____ 1. Within an object, actions are modeled using: A) variables. B) classes. C) methods. D) constants. E) None of these is correct. 2. Suppose that class ClassX is defined without an explicit superclass and with exactly two methods, methodA and methodB . The following legal application code is created: ClassX objectX = new ClassX(); System.out.println(objectX.toString()); This will result in: A) an exception being thrown – no such method. B) the invocation of the Object class's toString method. C) the string "object" appearing in the output stream. D) polymorphism. E) None of these is correct. 3. Which of the following structures did we classify as “implementation dependent”? A) Sorted List B) Graph C) Linked List D) Tree E) None of these is correct. 4. The following is a “reference” type. A) int B) long C) boolean D) String E) None of these is correct. 5. A(n) _____________ defines the structure of an object or a set of objects. A) class B) attribute C) application D) constructor E) method 1 © Copyright 2020 by P.E.P.
6. Objects can represent both: A) space and time efficiency. B) variables and constants. C) information and behavior. D) classes and inheritance. E) methods and constructors. 7. This structure is “last in, first out.” A) Array B) Map C) Stack D) Queue E) Tree 8. This structure is “first in, first out.” A) Array B) Map C) Stack D) Queue E) Tree 9. True or False? An object defines the structure of a class. A) True B) False 10. True or False? Java supports double inheritance, i.e., a class can have more than one superclass. A) True B) False Bonus Point Questions! (Answer as many as possible for extra credits). Give reasonable and detailed enough answers and provide examples as well where applicable. 1. For what purpose(s) are constructor methods used? Constructor methods are used to create new instances of a class and to instantiate objects of a class. 2. The Java reserved word ____ extends ____ indicates inheritance, i.e., we write "subclass ___ extends ___ superclass" (one word fits in both blanks). 3. To access the contents of a package from within a program, you must ___ import __ the package into your program (answer with a Java reserved word). 4. Describe an important difference between how Java handles primitive variables, such as int , and non- primitive variables, such as String . Primitive types are handled “by value” and nonprimitive types are handled “by reference”. A primitive variable holds the value of the variable. This is called direct addressing, where the memory location of that variable holds the actual value of the variable. An example of a primitive type is the int type. A non-primitive variable holds the reference to the value of the variable, or the address to the value of that variable. This is called indirect addressing, where the memory location of that variable holds the address to the location that holds the value of the variable. An 2 © Copyright 2020 by P.E.P.
example of a nonprimitive type is an array. 5. A real challenge! Write a section of code that declares a ten-element array of type Date named calendar and then uses a loop to instantiate and initialize the elements, in order, to December 1 through 10 of 2020. Hint- assume the Date class carries instance int variables as month, day, year. 3 © Copyright 2020 by P.E.P.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help