Classes with methods C#
This is the same code written in C#
# This is a sample Python script.
class myClass():
def method_one(self):
print("myClass method_one")
def method_two(self, AString):
print("myClass method_two" + AString)
class anotherClass(myClass):
def method_one(self):
myClass.method_one(self)
print("anotherClass method_one")
def method_two(self, AString):
print("anotherClass method2")
def main():
print("output statements")
print("c = myClass() \nc.method_one() \nc.method_two(\"This is a string to print\") ")
print("")
print("output is:")
c = myClass()
c.method_one()
c.method_two("This is a string to print")
print("")
print("")
print("output statements")
print("c2 = anotherClass() \nc2.method_one() \nc2.method_two(\"This is another string to print\")")
print("")
print("output is:")
c2 = anotherClass()
c2.method_one()
# in c2.method_two("This is another string to print") the string is not used. anotherClass method_two overrides the
# string used and prints its return
c2.method_two("This is another string to print")
if __name__ == '__main__':
main()
/home/michael/PycharmProjects/ClasswithMethods/venv/bin/python /home/michael/PycharmProjects/ClasswithMethods/main.py
output statements
c = myClass()
c.method_one()
c.method_two("This is a string to print")
output is:
myClass method_one
myClass method_twoThis is a string to print
output statements
c2 = anotherClass()
c2.method_one()
c2.method_two("This is another string to print")
output is:
myClass method_one
anotherClass method_one
anotherClass method2
Process finished with exit code 0