Chapter 5 Flashcards

1
Q

What is the definition of a class in Java?

A

A class is a blueprint for an object.

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

What does an object have in terms of state and behavior?

A

State = attributes = data; Behaviors = operations = class methods.

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

What are the two types of constructors in Java?

A
  • Default constructor
  • Parameterized constructor.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of the toString method in Java?

A

The toString method returns a string that contains the data in the object.

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

What are accessors and mutators?

A
  • Accessor: returns the current value of a variable.
  • Mutator: changes the value of a variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is instance data in the context of a class?

A

Instance data refers to data that is unique to each object instance.

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

What does the final modifier do in Java?

A

The final modifier is used to define constants.

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

How many visibility modifiers does Java have and what are they?

A

Java has three visibility modifiers: * public
* protected
* private.

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

What is the difference between public and private visibility in Java?

A
  • Public: can be referenced anywhere.
  • Private: can be referenced only within that class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is meant by local data in Java?

A

Local data refers to data declared within a method that can only be used in that method.

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

What is the scope of data in a Java program?

A

The scope of data is the area in a program where that data can be referenced.

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

What is the purpose of a method header?

A

A method header begins with the method’s name, return type, and parameter list.

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

What does a return statement do in a method?

A

The return statement specifies the value that will be returned to the calling location.

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

What are static methods and how are they invoked?

A

Static methods are invoked through their class name without needing to create an object first.

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

What happens when a variable is declared as static?

A

Only one copy of the variable exists, shared among all objects instantiated from the class.

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

What is the this reference in Java?

A

The this reference allows an object to refer to itself.

17
Q

What is method decomposition?

A

Method decomposition is breaking down a complex problem into smaller, manageable methods.

18
Q

How are parameters passed in Java methods?

A

Parameters are passed by value, meaning a copy of the actual parameter is stored in the formal parameter.

19
Q

What is the structure of a UML class diagram?

A

A UML class diagram consists of class names, attributes (data), and operations (methods).

20
Q

What do solid arrows represent in UML diagrams?

A

Solid arrows show that one class uses another by calling its methods.

21
Q

What are service methods in Java?

A

Service methods are public methods that provide the object’s services and can be invoked by clients.

22
Q

What is a support method in Java?

A

A support method assists a service method and should be declared with private visibility.

23
Q

Fill in the blank: A _______ method is used to give values to the instance data when the object is initially created.

A

constructor

24
Q

True or False: Instance variables exist as long as the object exists.

25
How are parameters in a Java method passed?
Parameters are passed by value ## Footnote A copy of the actual parameter is stored into the formal parameter in the method header
26
What is the relationship between actual and formal parameters when passing objects to methods?
They are aliases of each other ## Footnote An object is passed to a method by reference
27
What is method overloading?
Giving a single method name multiple definitions ## Footnote The signature of each overloaded method must be unique
28
What does the signature of an overloaded method include?
The number, type, and order of the parameters ## Footnote The return type is not part of the method signature
29
True or False: The return type of the method is part of the method signature in Java.
False
30
What determines which overloaded method is invoked?
The compiler analyzes the parameters ## Footnote It considers the number, type, and order of parameters
31
Fill in the blank: The method _______ is overloaded in Java.
println
32
What is the purpose of overloaded constructors?
To provide multiple ways to initialize a new object
33
What is the difference between passing a primitive variable versus an object as a parameter?
Primitive variables are passed by value, objects are passed by reference ## Footnote This affects how changes to parameters in methods are reflected
34
What are the syntax rules for overloaded methods?
The method names must be the same, but the signatures must differ ## Footnote This includes differing in the number, type, or order of parameters
35
What are some key topics expected on the exam from Chapter 5?
Creating a class, constructors, accessors, mutators, toString, testing a class, writing methods, calling/using methods