Exam 1 Flashcards
Object-oriented programming (OOP) is popular because:
- it enables reuse of previous code saved as classes
- which saves time because previously written code has been tested and debugged already
If a new class is similar to an existing class, the existing class can be:
Extended
This extension of an existing class is called:
Inheritance
Inheritance creates an is-a relationship, meaning the child is a more ___________________ of the parent.
Specific version
//mammal
drinkMothersMilk()
^
|
thinkCreatively()
A human is a:
Human has all the data fields and methods defined by:
Human is a __________ of mammal
Human may define other variables and methods that ______ contained in mammal
Mammal
Mammal
Subclass
Are not
The keyword ___________ creates an inheritance relationship
extends
Only ______________ need to be declared
Additional data fields
A notebook object contains the data fields declared in both the____________ and _____________ objects
Computer and notebook
If data fields are declared as __________ in the superclass, they are not directly accessible in the subclass
Private
If the execution of any constructor in a subclass does not invoke a superclass constructor—an explicit call to super()—java automatically invokes the __________________ for the superclass
No-parameter constructor
If no constructors are defined for a class, the _________________ for that class is provided by default
No-parameter constructors
If any _____________ are defined, you must explicitly define a no-parameter constructor
Constructor
Variables with a private visiability cannot be accessed by a:
Subclass
Variables with ___________ visibility are accessible by any subclass or any class in the same package
Protected
In general, it is better to use ____________ visibility and to restrict access to variables to accessor methods
Private
In an __________ or __________ relationship, one class is a subclass of the other class
is-a or inheritance
In an __________ or __________ relationship, one class has the other class as an attribute
has-a or aggregation
Methods in the class hierarchy which have the same name, return type, and parameters ___________ corresponding inherited methods
Override
When overriding a method, the method must have the same ________ and the same _________ and types of ________ in the same order. Otherwise, the method will overload
Name
Number
Parameters
It is good programming practice to use the __________ annotation in your code
@override
Polymorphism means:
Having many shapes
Polymorphism is a central feature of:
OOP
Polymorphism enables the JVM to determine at run time which of the classes in a hierarchy is referenced by a _________________ or ____________
Superclass variable or parameter
Why does polymorphism works because:
An object of a subclass can be used wherever an object of its superclass is expected
Polymorphism _____________ programming when writing methods with class parameters
Simplifies
What are the two parts of an ADT? Which part is accessible to a user and which is notExplain the relationships between an ADT and a class; between an ADT and an interface and berween an interface and classes that implement the interface.
of data elements and methods that data. user can access operations, but cannot the structure of the elementsA class ADT Ajava interface way to specify or ADT. A interface defines set of methods, and class that implements these and