0% completed
class Dog:
def bark(self):
return "Woof!"
fido = Dog()
print(fido.bark())
class Car:
__max_speed = 100 # Private variable
def drive(self):
return f"Driving max speed at {self.__max_speed} km/h"
my_car = Car()
print(my_car.drive())
class Animal:
def speak(self):
return "Some sound"
class Dog(Animal):
def speak(self):
return "Woof!"
pet = Dog()
print(pet.speak())
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
shape = Shape()
class BankAccount:
def __init__(self):
self.__balance = 0 # private attribute
def deposit(self, amount):
if amount > 0:
self.__balance += amount
self.__update_ledger(amount)
def __update_ledger(self, amount):
print(f"Deposited: {amount}")
account = BankAccount()
account.deposit(100)
.....
.....
.....