Data Structures Drill 1
What is the difference between a local variable and a field?
A local variable is declared in the body of a method and can be used only from the point at which it's declared through the end of the method declaration. A field is declared in a class, but not in the body of any of the class's methods. Also, fields are accessible to all methods of the class (with one exception: static fields are not accessible to non-static methods).
Method overriding
A method of the same name and argument list as a method in a parent class, so it replaces the parent method.
ClassCastException
An exception thrown when an object variable is cast with an incompatible class. 2.6: when code tries to downcast a tree to a Redwood an exception error is thrown at runtime
one way to make code reusable is to _________ or by combining data elements together with methods that operate on that data in a separate program module
Encapsulate
An interface is a class (True/False)
False
An array can store many different types of values (True/False)
False arrays can only store values of the same type
the nextInt( ) method throws this error if an integer choice is not entered
InputMismatchException
Method overloading (2)
It's possible to have several methods with the same name that each operate on different types or numbers of arguments. This feature is called method _______.
To String( ) Method
Java automatically applies this to an object referenced in a String expression
the nextInt( ) method will throw this exception when a program attempts to convert a non-numeric string to a numeric value
NumberFormatException
The superclass of all Java classes
Object
ArrayIndexOutOfBoundsException
Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.
What method should you always override if you want to represent an object's state?
To String( )
A major reason for the popularity of object-oriented programming is that it enables programmers to reuse previously written code saved as classes (True/False)
True
Each class that implements an interface must provide the complete definition of all methods declared in the interface (True/False)
True
Protected Visibility
a data field or method with this can be accessed in either the class defining it, in any subclass of that class, or any class in the same package
Contract
a java interface bridges this connection between the interface designer and the programmer who codes a class that implements the interface
Abstraction
a model of a physical entity or activity
The has-a relationship
between classes means that one class has the second class as an attribute
The is-a relationship
between classes means that one class is a subclass of the other
Which method of java.lang.Object compares an object to its argument?
boolean equals(Object obj)
This( )
call invokes the constructor for the current class whose parameter list matches the argument list
A class's public interface
consists of the class's public member functions
If a class declares constructors, the compiler will NOT create a _________
default
Method overloading
having multiple methods with the same name but different signatures in a class
No parameter Constructor
if no constructors are defined for a class this constructor will be provided by default
The Super call
in a class constructor invokes the superclass's constructor that has the corresponding argument list
Private visibility
is for members of a class that should not be accessible to anyone but the class, not even classes that extend it
Wrapper class
is used to store a primitive-type value in an object type
method declaration
method descriptions in an interface
Runtime error
occurs during program execution
Which of the following is considered a visibility modifier in Java? private inherit superclass string
private
what members do classes that are not part of a package have access to?
public members
Static variable
represents class wide information that's shared by all the objects of the class
Keyword new
requests memory from the system to store an object, then calls the corresponding class's constructor to initialize the object
If a method contains a local variable with the same name as one of its class's fields, the local variable _______ the field in that method's scope.
shadows
Java Interface
specifies the names, parameters, and return values of the ADT methods without specifying how the methods perform their operations or how the data is internally represented
abstract data type
the combination of data together with its methods