extraa Flashcards
(37 cards)
Why close files?
When a file is “opened,” the operating system marks the file as locked, generally so it can’t be deleted by other processes while it’s being used. myFile.close() undoes the lock, allowing the operating system and other processes to do what it wishes with the file. It also releases any system resources associated with the stream.
What happens if a parameter is passed by value?
a copy of the variable is passed to the subroutine where it is treated as a local variable thus protecting it from being changed by the subroutine but also using additional memory space. It is destroyed when the subroutine has completed.
What happens if a parameter is passsed by reference
the reference to the memory location of the variable itself is passed Therefore if the value of the variable is changed, it remains changed after the subroutine ends. A literal value can’t be passed by reference obviously as it has no reference (more applicable to recursive subroutines).
If it is not stated will parameters be passed by value or by reference
By value
How do you do by value and by ref?
procedure calculateTotal(x:byVal, y:byRef)
What is encapsulation?
All of the object’s attributes are contained and hidden in the object by giving them the private access modifier. They are accessed through public getter and setter methods.
What is instantiation?
The process of creating an instance of a class.
What is a class?
A blueprint for creating an object.
What is an access modifier?
For example public and private which can be applied to attributes and methods in the class. Private means the attribute or method can not be accessed by code in another class while public means it can.
What is an atribute?
A specific piece of data representing a particular characteristic of an object.
What is a constructor?
A method that is called when creating an instance (object) of a class.
What is an object?
Instance of a class
What is OOP?
A programming paradigm which classifies real world objects into classes and encapsulates the object’s attributes and behaviours.
What are methods?
for example getters and setters and other subroutines that define the behaviour of the object.
What is inheritance?
A mechanism that allows an instance of a class to inherit attributes and methods from another class (the superclass/parent class). It can also have methods/attributes of its own.
Subclass
A class that inherits from another class is called a subclass (also a derived class, extended
class, or child class).
Superclass
The class from which the subclass inherits from is called a superclass (or parent class).
What is polymophism?
(many forms) The ability of an entity such as a variable, operator, method or object to have more than one form. There are multiple types of polymorphism. In OOP, the ability for classes that share a common superclass to have different implementations of a method with the same name is one example. This is called overriding.
What are the advantages of inheritence?
reusability and readability. When child class inherits the properties and functionality of parent class, we do not need to write the same code again in child class. This makes it easier to reuse the code, makes us write the less code and the code becomes much more readable
What are the disadvantages of inheritence?
When you choose to inherit from another class, you have coupled the two classes. What will happen if someone extends the base class? What will happen if someone changes the base class to inherit from another class? Your class may now have acquired attributes and methods that you are not aware of.
What is the idea of an insertion sort?
Repeat the following for each item in the list, excluding the first
Remember the current item as the key
Move every item before the key that is bigger than it forward
Place the key item before these larger items
Advantages of insertion sort?
Advantages
Easy to implement
Good for small data sets that are almost sorted
Insertion sort generally performs quicker than bubble sort and is therefore preferable
Disadvantages of insertion sort
Disadvantages
Does not scale well so is not good for large data sets
What is a bit shift?
An operation that moves the bits in a byte, nibble etc by a determined number of places to either the left or right.