Exam 1 Flashcards

1
Q

Object-oriented programming (OOP) is popular because:

A
  • it enables reuse of previous code saved as classes

- which saves time because previously written code has been tested and debugged already

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If a new class is similar to an existing class, the existing class can be:

A

Extended

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

This extension of an existing class is called:

A

Inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Inheritance creates an is-a relationship, meaning the child is a more ___________________ of the parent.

A

Specific version

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

//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

A

Mammal

Mammal

Subclass

Are not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The keyword ___________ creates an inheritance relationship

A

extends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Only ______________ need to be declared

A

Additional data fields

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A notebook object contains the data fields declared in both the____________ and _____________ objects

A

Computer and notebook

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

If data fields are declared as __________ in the superclass, they are not directly accessible in the subclass

A

Private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

No-parameter constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If no constructors are defined for a class, the _________________ for that class is provided by default

A

No-parameter constructors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If any _____________ are defined, you must explicitly define a no-parameter constructor

A

Constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Variables with a private visiability cannot be accessed by a:

A

Subclass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Variables with ___________ visibility are accessible by any subclass or any class in the same package

A

Protected

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In general, it is better to use ____________ visibility and to restrict access to variables to accessor methods

A

Private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In an __________ or __________ relationship, one class is a subclass of the other class

A

is-a or inheritance

17
Q

In an __________ or __________ relationship, one class has the other class as an attribute

A

has-a or aggregation

18
Q

Methods in the class hierarchy which have the same name, return type, and parameters ___________ corresponding inherited methods

A

Override

19
Q

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

A

Name
Number
Parameters

20
Q

It is good programming practice to use the __________ annotation in your code

A

@override

21
Q

Polymorphism means:

A

Having many shapes

22
Q

Polymorphism is a central feature of:

A

OOP

23
Q

Polymorphism enables the JVM to determine at run time which of the classes in a hierarchy is referenced by a _________________ or ____________

A

Superclass variable or parameter

24
Q

Why does polymorphism works because:

A

An object of a subclass can be used wherever an object of its superclass is expected

25
Q

Polymorphism _____________ programming when writing methods with class parameters

A

Simplifies

26
Q

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.

A

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