teslariu

privado oop

Sep 26th, 2022
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # metodos privado
  5.  
  6. class Base:
  7.    
  8.     def funcion(self):
  9.         print("Metodo publico")
  10.        
  11.     def __funcion(self):
  12.         print("Metodo privado")
  13.        
  14.        
  15. class Derivada(Base):
  16.     def __init__(self):
  17.         Base.__init__(self)
  18.        
  19.     def llamar_publico(self):
  20.         self.funcion()
  21.    
  22.     def llamar_privado(self):
  23.         self.__funcion()
  24.        
  25.        
  26.  
  27. objeto1 = Base()
  28. objeto1.funcion()
  29.  
  30. objeto2 = Derivada()
  31. objeto2.llamar_publico()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment