Java

¡Supera tus tareas y exámenes ahora con Quizwiz!

Instance variables declared final do not or cannot

be modified after they are initialized

Assigning a subclass reference to a superclass variable is safe ________.

because the subclass object is an object of its superclass

Private fields of a superclass can be accessed in a subclass ______.

by calling public or protected methods declared in the superclass.

For which of the following would polymorphism not provide a clean solution?

A program to compute a 5% savings account interest for a variety of clients.

Which of the following class members should usually be private?

Variables (or fields)

All of the following methods are implicitly final except ________.

a method in an abstract class

Interfaces can have ________ methods.

any number of

Every object in Java knows its own class and can access this information through method .

getClass

The UML distinguishes an interface from other classes by placing the word "interface" in above the interface name.

guillemets ' '

Which keyword is used to specify that a class will define the methods of an interface?

implements

The default implementation of method clone of Object performs a ________.

shallow copy

We may need to modify all the subclasses of the superclass if the superclass implementation changes. (T/F)

true

which of the following class members should usually be private?

variable (or fields)

Having a this reference allows ________.

-a method to refer explicitly to the instance variables and other methods of the object on which the method was called -a method to refer implicitly to the instance variables and other methods of the object on which the method was called -an object to reference itself

Which of the following is not possible?

A class that inherits from two classes.

What happens when this is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor?

A compilation error occurs.

Which statement best describes the relationship between superclass and subclass types?

A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.

All of the following methods are implicitly final except:

a method in an abstract class.

Which of the following could be used to declare abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)?

public abstract int method1();

In Java SE 7 and earlier, an interface may contain ________.

public static final data and public abstract methods

Which method changes the text the label displays?

setText

A constructor cannot ________.

specify return types or return values

A final field should also be declared ________ if it is initialized in its declaration.

static

Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?

super

A subclass object can assign an invalid value to the superclass's instance variables, thus leaving an object in an inconsistent state. (T/F)

true

Abstract superclasses may contain data

true

Methods and instance variables can both be either public or private. (T/F)

true

Subclass methods are more likely to be written so that they depend on the superclass's data implementation. (T/F)

true

Which method returns an array of the enum's constants?

values

The default equals implementation of class Object determines ________.

whether two references refer to the same object in memory

Using the proceed keyword also gives a member _______.

package access

Using the protected keyword also gives a member ________.

package access

Superclass methods with this level of access cannot be called from subclasses.

private

Superclass methods with tis level of access cannot be called from subclasses

private

Polymorphism enables you to ________.

program in the general

Which interface is specifically intended to be implemented by classes that can be used with the try-with-resources statement?

AutoCloseable

Any concrete subclass that extends class Foo ________.

Both must implement a method called calculate and will not be able to access the instance variable a.

Using public set methods helps provide data integrity if ________.

Both the instance variables are private and the methods perform validity checking.

Objects are marked for garbage collection by method finalize. (T/F)

False

The static method ________ of class String returns a formatted String.

Format

When no access modifier is specified for a method or variable, the method or variable

Has package access

Composition is sometimes referred to as a(n) ________.

Has-a relationship

Class ________ represents an image that can be displayed on a JLabel.

ImageIcon

inheritance is sometimes referred to as a(n) ________.

Is-a relationship

Every class in Java, except ________, extends an existing class.

Object

Which of the following is not a superclass/subclass relationship?

Sailboat/Tugboat

Which interface is used to identify classes whose objects can be written to or read from some type of storage or transmitted across a network?

Serializable

When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable?

The program compiles and runs because the instance variables are initialized to their default values.

When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor doesn't assign a value to an instance variable?

The program complies and runs because the instance variables are initialized to their default values.

A class that implements an interface but does not declare all of the interface's methods must be declared ________.

abstract

A(n) ________ class cannot be instantiated.

abstract

Which of the following statements about abstract superclasses is true?

abstract superclasses may contain data.

get methods are also commonly called ________ methods.

accessor

BigDecimal gives you control over how values are rounded. By default ________.

all calculations are exact and no rounding occurs

Which superclass members are inherited by all subclasses of that superclass?

protected instance variables and methods

An interface ________.

can be instantiated

Non-abstract classes are called ________.

concrete classes

Overriding a method differs from overloading a method because ________________.

override methods have the same signature

Polymorphism allows for specifics to be dealt with during ________.

execution

A static method can call instance methods directly.(T/F)

false

A superclass object is a subclass object.

false

Anonymous methods provide a shorthand notation for creating lambdas.

false

If the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly.

false

It's OK to any of a class's methods from its constructors.

false

The BigDecimal method format receives a double argument and returns a BigDecimal object that represents the exact value specified. (t/f)

false

The compiler always creates a default constructor for a class. (T/F)

false

Use the access modifier package to give a method or variable package access. (T/F)

false

When you enhance an existing interface with default methods- any class that implemented the original interface will break.

false

With non-static interface methods, helper methods can now be declared directly in interfaces rather than in separate classes.

false

Classes and methods are declared final for all but the following reasons ________.

final methods are static

Which syntax imports all static members of class Math?

import static java.lang.Math.*.

When overriding a superclass method and calling the superclass version from the the subclass method, failure to prefix the superclass method name with they keyword super.() in the superclass method call causes

infinite recursion

To avoid duplicating code, use ___ rather than _____.

inheritance, the "copy-and-paste" approach

If the superclass contains only abstract method declarations, the superclass is used for ________.

interface inheritance

If the superclass contains only abstract method declarations, the super class is used for ______.

interface inheritance.

It is a UML convention to denote the name of an abstract class in ________.

italics

When a superclass variable refers to a subclass object and a method is called on that object, the proper implementation is determined at execution time. What is the process of determining the correct method to call?

late binding

Set methods are also commonly called ________ methods

mutator

An advantage of inheritance is that

objects of a subclass can be treated like objects of their superclass

An advantage of inheritance is that ________.

objects of a subclass can be treated like objects of their superclass


Conjuntos de estudio relacionados

L'amour et le mariage (love and marriage)

View Set

7.1 The Kidney: Function, Anatomy, the Nephron and Glomerulus

View Set