In: Computer Science
In Python
What is a class?
A class is a collection of method and variables. It is a blueprint that defines the data and behavior of a type.
------
What is a property as it relates to a class?
Python @property is one of the built-in decorators. The main purpose of any decorator is to change your class methods or attributes in such a way so that the user of your class no need to make any change in their code.
------
What is a method as it relates to a class?
A function that's part of a class is a method.
-----
What is an object?
It is a basic unit of class and it has the behaviour of the class.
-----
How do you create an object?
class ClassName():
# class definition
def main():
MyObject = ClassName()
--------
What is an instance variable versus a class level variable?
Instance variables are variables used for data that is unique to a particular instance.
Class Variables are variables that are shared by all instances of a class.
------
What is a constructor?
A constructor is a special kind of method that Python calls when it instantiates an object using the definitions found in your class.
------
Is a constructor always required? Does it depend on the language?
No, constructor is not always required.
A default (no-argument) constructor is automatically created only when you do not define any constructor yourself.
-----
What is and what is the benefit of inheritance?
Inheritance is a feature of object-oriented programming that allows code reusability when a class includes property of another class.
-----
What is and what is the benefit of encapsulation?
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. Another way to think about encapsulation is, it is a protective shield that prevents the data from being accessed by the code outside this shield.
------
What is and what is the benefit of polymorphism?
Polymorphism refers to the ability of OOPs programming languages to differentiate between entities with the same name efficiently.
-------
What is a Getter and Setter.....what are their purpose as it relates to encapsulation?
Getter and setter are class methods that gives or sets the value of a class member. It is useful in data hiding. It shows encapsulation.