Untitled

 avatar
unknown
plain_text
2 months ago
1.2 kB
8
Indexable
        print(f"Email: {self._email}")
        print(f"CNP: {self.__cnp}")

    # METODA PROTECTED
    def _verifica_email(self):
        return "@" in self._email

    # METODA PRIVATE
    def __mascheaza_cnp(self):
        return self.__cnp[:3] + "********"

    # Metodă publică prin care putem folosi o metodă privată
    def afiseaza_cnp_mascat(self):
        print(f"CNP mascat: {self.__mascheaza_cnp()}")


class Student(Persoana):
    def __init__(self, nume, email, cnp, grupa, medie):
        super().__init__(nume, email, cnp)

        # PUBLIC
        self.grupa = grupa

        # PROTECTED
        self._medie = medie

        # PRIVATE
        self.__numar_matricol = "STU12345"

    def afiseaza_student(self):
        print("--- Student ---")
        print(f"Nume: {self.nume}")       # acces public
        print(f"Email: {self._email}")    # acces protected, permis in subclasa
        print(f"Grupa: {self.grupa}")
        print(f"Medie: {self._medie}")

        # Nu putem accesa direct self.__cnp, deoarece este private în clasa Persoana
        # print(self.__cnp)  # ar produce eroare

    def verifica_date_student(self):
        if self._verifica_email():
            print("Emailul studentului este valid.")
Editor is loading...
Leave a Comment