Object oriented programming 1 Flashcards
What are attributes?
Attributes are specific properties of an object.
"Matz".length # ==> 4 Matz is an object .lenght is a method 4 is an attribute
What is a class?
A class is a way to organize and produce objects with similar attributes and methods.
Basically a blueprint.
How do you write a class?
class ClassName # some code end
You use CamelCase for the class name
What is the initialize method?
The initialize method is used to boost up the class, it gives us attributes that we can start up with.
It will run every time we create the class.
What is an instance variable?
An instance variable makes the variable available in other parts of the application
What is scope of a variable?
The scope of a variable is where the variable is accessible for the rest of the program. Some variables are not accessible to other parts of the program.
What are global variables?
Variables that are available everywhere
What are local variables?
Variables that are only available inside certain methods.
How do you write instance variables?
you write them with a @
@variable_name
How do you write class variables?
You write them with two @@
@@variable_nameHow do yo wr
How do you write global variables?
1) You just define the variable outside the method or class.
2) If you are writing the global variable from inside a method or a class just write $ before the variable.
How should you create variables?
You should only create them with a limited scope so that they can only be changed from a few places.
What is inheritance?
inheritance is the process by which one class takes on the attributes and methods of another.
What is the inheritance syntax?
you use the < symbol to show the inheritance.
class DerivedClass < BaseClass # Some stuff! end
This means that DerivedClass inherits from BaseClass.
What is override?
If you want a class to not to take the attributes of the baseclass