LAB 5 Flashcards

(39 cards)

1
Q

is an important feature of object-oriented programming in Java. It allows for one class (child class) to inherit the fields and methods of another class (parent class). For instance, we might want a child class Dog to inherent traits from a more general parent class Animal.

A

Inheritance

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

In simple Java programs, you may work with just one class and one file. However, as your programs become more complex you will work with multiple classes, each of which requires its own file. Only one of these files in the Java package requires a ______ method, and this is the file that will be run in the package.

A

main()

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

For example, say we have two files in our Java package for two different classes:

Shape, the is the ______ class
Square, the ______ class.

A

parent class.
child class.

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

In Java, a child class inherits its parent’s fields and methods, meaning it also inherits the parent’s constructor. Sometimes we may want to modify the constructor, in which case we can use the _____ method, which acts like the parent constructor inside the child class constructor.

A

super() method

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

keeps a parent class member accessible to its child classes, to files within its own package, and by subclasses of this class in another package.

A

protected

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

Adding ____ before a parent class method’s access modifier makes it so that any child classes cannot modify that method - it is immutable.

A

final

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

Java incorporates the object-oriented programming principle of ____

_______ allows a child class to share the information and behavior of its parent class while also incorporating its own functionality. This allows for the benefits of simplified syntax and reduced cognitive overload for developers.

A

polymorphism.

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

In Java, we can easily ______ parent class methods in a child class.

______ a method is useful when we want our child class method to have the same name as a parent class method but behave a bit differently.

A

override / overriding

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

In order to override a parent class method in a child class, we need to make sure that the child class method has the following in common with its parent class method:

A

-Method name
-Return type
-Number and type of parameters

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

In Java, polymorphism allows us to put instances of different classes that share a parent class together in an __________

For example, if we have an Animal parent class with child classes Cat, Dog, and Pig we can set up an ____ with instances of each animal and then iterate through the list of animals to perform the same action on each.

A

array or ArrayList.

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

is when a child class inherits from a parent class.

A

Single Inheritance

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

is when a child class inherits from a parent class which in turn inherits from another parent class.

A

Multilevel Inheritance

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

is when a child class inherits from a parent class and there is another sibling class that also inherits from the same parent class.

A

Hierarchical Inheritance

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

are reusable pieces of code in classes.

A

Methods

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

The difference between a method and a function is that

A

methods are always related to a class or an object

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

Methods consist of at least the following elements:

A

Return type: The type of the value that is returned from the method

Name: The name of the method

17
Q

The ____ of a method should describe as much as possible what the method is doing.

18
Q

is described by a data type and a name.

can be used to access the value inside the method body. A method without any ______ must have empty parenthesis () after the method name.

19
Q

can change how a method is allowed to be called (public, protected, private, package private), if the method is working on object state or should be executable without creating an object out of a class (static), or if the method is allowed to be replaced by inherited classes (final).

20
Q

(4) Visibility Modifiers

A

public
private
package private
protected

21
Q

Methods declared as ____ can be called from everywhere, inside and outside of the object or the class.

22
Q

Methods declared as _____ can only be called from inside the object or the class.

23
Q

Methods declared as ______ can only be called from classes within the same package.

A

package private

24
Q

Methods declared as _______ can only be called from inside the class or from inside classes inherited from that class.

25
the ___ keyword prevents methods from being overwritten in inherited classes. It can be combined with other modifiers.
final
26
Methods can throw ______. An example of this is trying to access a file that doesn’t exist.
Exceptions
27
Everything between { and } is called the ________ The ______ contains the actual code, statements, or logic that is executed when the method is called.
body of the method. Body
28
Static methods and variables are declared as static by using the _____ keyword upon declaration.
static
29
are associated with the class as a whole, not objects of the class. Both are used by using the name of the class followed by the . operator.
Static Methods and Variables
30
Static methods cannot access or change the values of
instance variables.
31
Both non-static and static methods can access or change the values of
static variables.
32
In Java, the keywords _____ and _____ define the access of classes, instance variables, constructors, and methods.
public and private
33
restricts access to only the class that declared the structure, while
private
34
allows for access from any class.
public
35
is a technique used to keep implementation details hidden from other classes. Its aim is to create small bundles of logic.
Encapsulation
36
In Java, instance variables are encapsulated by using the ____ keyword. This prevents other classes from directly accessing these variables.
private
37
In Java, _____ return the value of a private variable. This gives other classes access to that value stored in that variable. without having direct access to the variable itself.
accessor methods
38
In Java, ______ reset the value of a private variable. This gives other classes the ability to modify the value stored in that variable without having direct access to the variable itself.
mutator methods
39
take one parameter whose type matches the type of the variable it is modifying. these methods usually don’t return anything.
Mutator methods