Lecture 4 Flashcards
What is a reference type?
A reference type, is a data type, which is not directly stored. This means that the “memory” to which a certain variable points, is not the value of the variable, but a memory address containing one or more values that belong to this variable.
What happens when using “==” on reference types?
It compares the addresses and not the actual values.
What two things are important when implementing the equals method?
The parameter has to be of type Object (which means that we have to check if it is of the same class as the object we’re comparing to) and we have to make sure to properly check if all values of the objects are equal, which in the case of reference types means that we can’t use “==”
What is an object?
an instance of a class
What is a class?
A blueprint for objects, which defines the attributes that they have and the “things you can do with them”, or methods.
What does ‘Static’, in the signature of a method, mean?
It means that this method cannot be called on an object of this class, but has to be called on the “entire” class.
What does ‘static’, in the context of an attribute, mean?
it means that this attribute is constant across all instances of this object.
How are ‘private’ and ‘public’ shown in UMF?
private: -
public: +
What are 2 possible goals of encapsulation?
Hiding the implementation to users / customers
and
protecting yourself / programmers against accidentally reassigning the value.
What is the consequence of “pass by value” when passing reference types to a method?
Since the reference types are pointing towards memory locations, this pointer can not be changed, as was the case for direct data types, but the contents of the memory to which the reference type is pointing CAN be changed!