OCJP

Interface in Python

Python Does not provide interface like Java. You can achieve this using class like:

class Uni:
    def Study(self):
        raise NotImplementedError("Must Implement Study")
                                  
    def Exam(self):
        raise NotImplementedError("Must Implement Exam")


class College(Uni):
    def __init__(self):
        pass
    def Study(self):
        print("Study in College")

    def Exam(self):
        print("Exam in College")
    
U= College()
U.Study()
U.Exam()

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?