-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.py
40 lines (27 loc) · 1.05 KB
/
class.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Student:
year = 1
num_of_students = 0
def __init__(self, first, last, email): # Costruttore self è la referenza all'oggetto stesso (this di Java)
self.first = first
self.last = last
self.email = email
Student.num_of_students += 1
def fullname(self): # Metodo
return '{} {}'.format(self.first, self.last) # self MUST be used
s1 = Student('Alessandro', 'Versace', 'aleversace98@gmail.com')
s2 = Student('Me', "NotMe", "menotme@gmail.com")
print(s1.fullname())
print('\n')
print(s2.__dict__)
print('\n')
print(Student.__dict__)
print('\n')
s1.year = 2
print(s1.__dict__)
print('\n')
print(Student.num_of_students)
# Interfaces: methods with "visibility" outside the object.
# Encapsulation: restrict access of some components (Then we can control access with methods ie. get() and set())
# Inheritance: Sub-Classes inherit attributes and methods from their "parents" Classes (Super Classes).
# A Super class, B sub-class -> We say "B extends A".
# Can be single or multiple.