Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:43:31+00:00 2026-05-24T12:43:31+00:00

In the following code i am trying to implement inheritance and polymorphism properties,My question

  • 0

In the following code i am trying to implement inheritance and polymorphism properties,My question is obj1.hello3("1param","2param") obj1.hello3("11param") are these statements not correct what would be the correct way of doing this

  #!/usr/bin/python

  class test1:
     c,d = ""
     def __init__(self,n):
        self.name = n
        print self.name+"==In a"
     def hello1(self):
        print "Hello1"
     def hello3(self,a,b):
        #print "Hello3 2 param"+str(a)+str(b)
        #print "ab"+str(self.a)+str(self.b)+"Hello1"
        print "Hello3 2 param"

     def hello3(self,a):
        #print "a"+str(self.a)+"Hello1"
        print "Hello3 1 param"+str(a)

  class test2(test1):
     def __init__(self,b):
        test1.__init__(self, "new")
        self.newname = b
        print self.newname+"==In b"
     def hello2(self):
        print "Hello2"

  obj= test1("aaaa")
  obj1=test2("bbbb")
  obj1.hello1()
  obj1.hello2()
  obj1.hello3("1param","2param")
  obj1.hello3("11param")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:43:31+00:00Added an answer on May 24, 2026 at 12:43 pm

    You are trying to implement method overloading rather than inheritance and polymorphism.

    Python does not support overloading in the way that C++, Java, C# etc. do. Instead, to achieve what you want in Python, you need to use optional parameters.

    def hello3(self,a,b=None):
        if b is None:
            print "Hello3 1 param", a
        else:
            print "Hello3 2 param", a, b
    
    ...
    
    obj1.hello3("a")#passes None for b param
    obj1.hello3("a", "b")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement http://github.com/bengottlieb/Twitter-OAuth-iPhone/tree/master into my code. I'm following the Demo provided and
I am trying to implement Quick Sort algorithm. Following code works for unique elements
I was trying to implement the following code: var action = function (e) {
I am trying to implement a linked list using following code, I got segment
I'm trying to implement an increment in prolog, and have written the following code:
I'm trying to implement CSS transition on the hyperlinks, I'm trying following code, but
I'm trying to implement the following code in a html document: $(function () {
I'm trying to implement AES encryption in my application. I have the following code
i am trying to implement following Code... String updateQuery =INSERT INTO MAAccounts(userId, accountId, accountType,
I'm trying to implement the following code in Ruby and getting stuck on it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.