Extending Classes in Video Game Development
30 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Why is the collection of the keys of a map a ______ and not a list?

set

Why is the collection of the values of a map not a ______?

set

Suppose you want to track how many times each word occurs in a document. Declare a suitable ______ variable.

Map

What is a ______? Give a possible use for such a structure.

<p>Map</p> Signup and view all the answers

A queue Allows you to add items to one end of the queue (the tail) Remove items from the other end of the queue (the head) Items are removed in the same order in which they were added First- in, first-out or FIFO order ❖ To visualize a queue, think of people ______ up.

<p>lining</p> Signup and view all the answers

The Queue interface in the standard Java library has: an add method to add an element to the tail of the queue, a remove method to remove the head of the queue, and a ______ method to get the head element of the queue without removing it.

<p>peek</p> Signup and view all the answers

The method walk() is ______, therefore it cannot be overridden.

<p>static</p> Signup and view all the answers

For a binding of static, private and final methods, the type of the class is determined by the ______ at compile time.

<p>compiler</p> Signup and view all the answers

In dynamic binding, if an object o invokes a method p, the JVM searches the implementation in classes C1, C2, ..., Cn-1, and ______.

<p>Cn</p> Signup and view all the answers

In Java, the most general class is ______ class.

<p>Object</p> Signup and view all the answers

Dynamic binding occurs at ______.

<p>runtime</p> Signup and view all the answers

Overriding occurs when methods are not static, private, or ______.

<p>final</p> Signup and view all the answers

To add new objects to our video game: Build a class that extends SpaceObject and provides its own draw method implementation. When objects of that class appear in the SpaceObject collection, the screen-manager code invokes method draw, exactly as it does for every other object in the collection, regardless of its type. So the new objects simply plug in without any modification of the screen manager code by the programmer. Tips to Remember… ❖ Polymorphism enables you to deal in generalities and let the execution-time environments handle the specifics.❖ You can tell objects to behave in manners appropriate to those objects, without knowing their specific types as long as they belong to the same inheritance hierarchy. Tips to Remember…(2) ❖ Polymorphism promotes extensibility: Software that invokes polymorphic behavior is independent of the object type to which the messages are sent. Therefore, new object types that can respond to the existing method calls can be added into a system without changing the base system. Only the client code that instantiates new objects must be changed to accommodate new types.

<p>blank</p> Signup and view all the answers

Build a class that extends SpaceObject and provides its own ______ method implementation.

<p>draw</p> Signup and view all the answers

When objects of that class appear in the SpaceObject collection, the screen-manager code invokes method ______, exactly as it does for every other object in the collection, regardless of its type.

<p>draw</p> Signup and view all the answers

Polymorphism enables you to deal in generalities and let the ______ handle the specifics.

<p>execution-time environments</p> Signup and view all the answers

You can tell objects to behave in manners appropriate to those objects, without knowing their specific types as long as they belong to the same ______ hierarchy.

<p>inheritance</p> Signup and view all the answers

Software that invokes polymorphic behavior is independent of the object type to which the messages are sent. Therefore, new object types that can respond to the existing method calls can be added into a system without changing the base system. Only the client code that instantiates new objects must be changed to accommodate new ______.

<p>types</p> Signup and view all the answers

Method sort sorts the elements of a List. The elements must implement the Comparable interface. The order is determined by the ______ order of the elements’ type as implemented by a compareTo method.

<p>natural</p> Signup and view all the answers

Method compareTo is declared in interface Comparable and is sometimes called the ______ comparison method.

<p>natural</p> Signup and view all the answers

The sort call may specify as a second argument a Comparator object that determines an alternative ______ of the elements.

<p>ordering</p> Signup and view all the answers

The Comparator interface is used for sorting a Collection’s elements in a different ______.

<p>order</p> Signup and view all the answers

The static Collections method reverseOrder returns a Comparator object that orders the collection’s elements in ______ order.

<p>reverse</p> Signup and view all the answers

Static Collections method binarySearch locates an object in a List. If the object is found, its index is returned. If the object is not found, binarySearch returns a ______ value.

<p>negative</p> Signup and view all the answers

Generic programming is the creation of programming constructs that can be used with many different types. In Java, this is achieved with type parameters or with ______.

<p>inheritance</p> Signup and view all the answers

Java Generics enables the programmer to create a single class, interface, and method which can be used with different types of objects, thus enabling code ______.

<p>reuse</p> Signup and view all the answers

Primitive data types such as int, char, and float do not work with generics. For example, ______ is not allowed.

<p>ArrayList</p> Signup and view all the answers

A generic class has one or more type parameters. A type parameter for ArrayList denotes the element type, for example: public void add(E element) public E get(int index). Here, 'E' represents the ______ type.

<p>element</p> Signup and view all the answers

Type parameters in Java generics can be instantiated with class or interface types. For example, ArrayList uses String as the type parameter. However, you cannot use a primitive type like int directly as a type parameter, for instance: ArrayList is ______.

<p>Wrong!</p> Signup and view all the answers

In generic programming, the objective is to create programming constructs that can work with various types. This flexibility is achieved through the use of type parameters or ______.

<p>inheritance</p> Signup and view all the answers

More Like This

Use Quizgecko on...
Browser
Browser