saturngod said:
1. Encapsulation
2. Inheritance
3. Polymorphism
class SquareSumComputer:
def __init__(self, a, b):
self.a = a
self.b = b
def transform(self, x):
return x * x
def inputs(self):
return range(self.a, self.b)
def compute(self):
return sum(self.transform(value) for value in self.inputs())
class CubeSumComputer(SquareSumComputer):
def transform(self, x):
return x * x * x
class Animal:
def __init__(self, name): # Constructor of the class
self.name = name
def talk(self): # Abstract method, defined by convention only
raise NotImplementedError("Subclass must implement abstract method")
class Cat(Animal):
def talk(self):
return 'Meow!'
class Dog(Animal):
def talk(self):
return 'Woof! Woof!'
animals = [Cat('Missy'),
Dog('Lassie')]
for animal in animals:
print animal.name + ': ' + animal.talk()
PhyoMyanmar said:Yes ... Java is the most appropriate for learning OOP
:D
htun linn aung said:Yeah!thank bro for answering mystery,please continue about of that weird.
By sample code.
Welcome MZ's member to discuss this thread.
လှိုက်လှဲစွာကြိုဆိုပါသည်။ ယခု ပထမဆုံးအကြိမ် ရောက်ဖူးခြင်းဖြစ်ပါသလား? ဝင်ရောက် ဆွေးနွေး မေးမြန်းလိုပါလျှင် အောက်တွင်ဖော်ပြထားသော button များမှတဆင့် ဝင်ရောက် ဆွေးနွေးနိုင်သကဲ့သို့ အဖွဲ့ဝင်အသစ်အနေဖြင့်လည်း လျှောက်ထားနိုင်ပါတယ်။