Return to Home Page
      Blog     Consulting     Seminars     Calendar     Books     CD-ROMS     Newsletter     About     FAQ      Search
 

Is there a reason why you have to explicitly call a base-class constructor within the derived-class constructor? Why isn't this done automatically, like in C++? It seems to me that this is inconsistent with the economy of Python that you've shown in this chapter. For that matter, the same could be said about explicitly passing the self argument.

f  e  x


Hmm... Looks like python has some problems (atleast in windows) printing the output as expected ....
I have python 2.2 and the output of the code is...

Inside Simple2 constructor
Inside the Simple constructor
Called from display(): Overridden show() method
Simple2 constructor argument
Overridden show() method
Simple2 constructor argument
Inside main: Overridden show() method
Simple2 constructor argument
Overridden show() method
Simple2 constructor argument
Not derived from Simple

Note the line....
Called from display(): Overridden show() method
is in one line and so is ...
Inside main: Overridden show() method

f  e  x


The show() called from showMsg() is not the base-class version. Why? It will allow the derived-class change the base-class behavior in complete ignorance when I just want to override show() but expect the behavior of showMsg() is not changed.

f  e  x


"Simple2 is inherited from Simple, and in the constructor, the base-class constructor is called"

What about multiple inheritance? What's the syntax for calling the base classes constructors?

f  e  x


Hai!
I wanted to know how executed the script, in a standalone machine ie in the python interpreter ,
I was not able to execute ..

f  e  x


Well,I am new to any type of programming but I think that someone missed warning :# Overriding a base-class method.
As I see it the base class version of show()was overriden by
defining method again in subclass (with different output).You can test this by removing def show() block.

f  e  x



Add your comment below. Use an empty line between each paragraph. Paragraphs will be automatically formatted, and single carriage returns will be respected. Use <code> to begin a code block, and </code> to end a code block. Your email address will not be visible to spam harvesters or used in any way except to contact you with further questions.

Your Email Address:

Search     Home     WebLog     Consulting     Seminars     Calendar     Books     CD-ROMS     Newsletter     About     Contact     Site Design     Server Maintenance     Powered by Zope
©2007 MindView, Inc.