Python Forum
Child class inheritance issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Child class inheritance issue
#3
(Apr-21-2022, 10:28 AM)menator01 Wrote: Please use tags when posting code.
Maybe something like this
class A:
    def __init__(self, name, age):
        self.name = name
        self.age = age
    def details(self):
        print (self.name)

obj = A('Ramesh', 62)
obj.details()

class B:
    def __init__(self, name, id):
        self.name = name
        self.id = id
    def details1(self):
        print (self.name)
obj = B('Ram', 1234)
obj.details1()

class C(A,B):
    print("Just inside class C")

    def __init__(self):
        A.__init__(self, 'name me', 23) # calling class A constructor
        print('Calling Class A constructor')

    def get_details(self):
        A.details(self)
        print(A.details(A.self.name))

obj = C()
obj.details()
Output:
Ramesh Ram Just inside class C Calling Class A constructor name me


Thanks a ton for immediate response to my very basic in python. Pardon me for asking such questions, but wish to learn on my own. Real pleasure and elated to get immediate response. Thank you once again.
Note: will use tags in future.
Reply


Messages In This Thread
Child class inheritance issue - by eakanathan - Apr-21-2022, 09:32 AM
RE: Child class inheritance issue - by menator01 - Apr-21-2022, 10:28 AM
RE: Child class inheritance issue ----"menator01" pid='156269' - by eakanathan - Apr-21-2022, 11:19 AM
RE: Child class inheritance issue - by deanhystad - Apr-21-2022, 12:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  super() and order of running method in class inheritance akbarza 7 859 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
Question __init__ of Child Class zero_fX0 4 1,847 Mar-22-2023, 05:23 PM
Last Post: deanhystad
  Using one child class method in another child class garynewport 5 1,702 Jan-11-2023, 06:07 PM
Last Post: garynewport
  Importing issues with base class for inheritance riccardoob 5 4,830 May-19-2021, 05:18 PM
Last Post: snippsat
  3D vector class with inheritance from 2D vector class buss0140 4 3,240 Dec-20-2020, 08:44 PM
Last Post: deanhystad
  Class inheritance oclmedyb 3 2,319 Dec-09-2020, 04:43 PM
Last Post: deanhystad
  Can we access instance variable of parent class in child class using inheritance akdube 3 14,060 Nov-13-2020, 03:43 AM
Last Post: SalsaBeanDip
  Issue referencing new instance from other class nanok66 3 2,272 Jul-31-2020, 02:07 AM
Last Post: nanok66
  Performance degradation with IO class inheritance wsygzyx 2 2,175 Jun-18-2020, 06:02 PM
Last Post: wsygzyx
  calling on a method from one class into another class which is not a child NABA 5 2,898 Apr-29-2020, 07:49 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020