Methods and References Flashcards

1
Q

What are reference diagrams?

A

Reference diagrams are diagrams that show how data is stored by objects and how computation is performed on those objects. They can help developers understand how data structures are constructed and how objects interact with each other.

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

Why are reference diagrams useful?

A

Reference diagrams are useful because they help developers visualize the structure and behavior of complex systems. By understanding how objects are constructed and how they interact with each other, developers can write more efficient and effective code.

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

What types of data are represented in reference diagrams?

A

Reference diagrams can represent both class types and simple types. Class types are objects that are instances of a class, while simple types are basic data types like integers, booleans, and strings.

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

How do class types and simple types pass parameters?

A

Class types pass parameters by copying references to objects, while simple types pass parameters by copying values. When a class type is passed as a parameter, the reference to the object is copied, so any changes made to the object in the method will be reflected in the original object. When a simple type is passed as a parameter, a copy of the value is made, so any changes made in the method will not affect the original value.

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

What is the benefit of understanding reference diagrams before programming?

A

Understanding reference diagrams before programming can help developers create more effective and efficient code. By visualizing the structure and behavior of a system, developers can identify potential issues and design solutions that take advantage of the strengths of the system. This can save time and effort in the programming process, and result in better code overall.

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

How do you call a static method?

A

To call a static method, you use the name of the class followed by the method name, like this: ClassName.methodName(). For example, if you have a static method called incCheckins() in the Book class, you could call it like this: Book.incCheckins().

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

How do you call a non-static method?

A

To call a non-static method, you use the name of the object followed by the method name, like this: objectName.methodName(). For example, if you have an object called b1 of the Book class, and you want to call the setAuthor() method on that object, you could call it like this: b1.setAuthor(“Me”). Within the method, the object that the method was called on is referred to using the “this” keyword.

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

What is a static instance variable?

A

A static instance variable is a variable that is associated with a class, rather than with a particular instance of the class. This means that there is only one copy of the variable, which is shared among all instances of the class. Static instance variables are declared using the “static” keyword, and they can be accessed from within static methods.

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

What is a non-static instance variable?

A

A non-static instance variable is a variable that is associated with a particular instance of a class, rather than with the class itself. This means that each instance of the class has its own copy of the variable. Non-static instance variables are declared without the “static” keyword, and they can be accessed from within both static and non-static methods.

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

What is the difference between a static instance variable and a non-static instance variable?

A

The main difference between a static instance variable and a non-static instance variable is that a static instance variable is associated with the class, while a non-static instance variable is associated with a particular instance of the class. This means that there is only one copy of a static instance variable, which is shared among all instances of the class, while each instance of the class has its own copy of a non-static instance variable. Additionally, static instance variables can only be accessed from within static methods, while non-static instance variables can be accessed from both static and non-static methods.

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

Can a static method access a non-static instance variable?

A

No, a static method cannot access a non-static instance variable, because the variable is associated with a particular instance of the class, rather than with the class itself. To access a non-static instance variable from within a static method, you need to pass a reference to an instance of the class as a parameter.

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

Can a non-static method access a static instance variable?

A

Yes, a non-static method can access a static instance variable, because the variable is associated with the class, rather than with a particular instance of the class. However, you should be careful when accessing static instance variables from within non-static methods, because the value of the variable is shared among all instances of the class.

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

What happens when a value is passed as a parameter to a function?

A

A value is copied into a local parameter for the function.

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

What happens to the value passed as a parameter once the function terminates?

A

Once the function terminates, the value is destroyed.

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

For simple types, what is copied into the local parameter of a function?

A

For simple types, the actual value stored in the variable is copied into the local parameter of a function.

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

For class types, what is copied into the local parameter of a function?

A

For class types, a reference to an object is copied into the local parameter of a function.

17
Q

Do references to objects outside the method scope change when a method is called?

A

No, references to objects outside the method scope do not change when a method is called.

18
Q

For variable declarations of simple types, what is stored in the variable?

A

For variable declarations of simple types, the value stored in the variable is the actual value.

19
Q

For variable declarations of class types, what is stored in the variable?

A

For variable declarations of class types, a reference to the object is stored in the variable.

20
Q

What is an array of class types?

A

An array of class types is an array where each element of the array stores a reference to an object of that class.

21
Q

How do arrays of class types behave in parameter passing?

A

Arrays of class types behave like references in parameter passing.

22
Q

When an array of class types is created, where do the arrows initially point?

A

When an array of class types is created, initially all the arrows point nowhere (null).