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 8469865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:21:03+00:00 2026-06-10T16:21:03+00:00

I’m having trouble with my code. I’m trying to create a subclass which inherits

  • 0

I’m having trouble with my code. I’m trying to create a subclass which inherits the parent class’s attributes and methods but it doesn’t work. Here’s what I have so far:

class Employee(object): 
  def __init__(self, emp, name, seat):
    self.emp = emp
    self.name = name
    self.seat = seat

Something is wrong with the block of code below – the subclass.

Do I have to create the __init__ again? And how do I create a new attribute for the subclass. From reading questions, it sounds like __init__ in the subclass will override the parent class – is that true if I call it to define another attribute?

class Manager(Employee): 
  def __init__(self, reports):
    self.reports = reports
    reports = [] 
    reports.append(self.name) #getting an error that name isn't an attribute. Why? 

  def totalreports(self):
    return reports

I want the names from the Employee class to be in the reports list.

For example, if I have:

emp_1 = Employee('345', 'Big Bird', '22 A')
emp_2 = Employee('234', 'Bert Ernie', '21 B')

mgr_3 = Manager('212', 'Count Dracula', '10 C')

print mgr_3.totalreports()

I want reports = ['Big Bird', 'Bert Ernie'] but it doesn’t work

  • 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-06-10T16:21:04+00:00Added an answer on June 10, 2026 at 4:21 pm

    You never called the parent class’s __init__ function, which is where those attributes are defined:

    class Manager(Employee): 
      def __init__(self, reports):
        super(Manager, self).__init__()
        self.reports = reports
    

    To do this, you’d have to modify the Employee class’s __init__ function and give the parameters default values:

    class Employee(object): 
      def __init__(self, emp=None, name=None, seat=None):
        self.emp = emp
        self.name = name
        self.seat = seat
    

    Also, this code will not work at all:

      def totalreports(self):
        return reports
    

    reports‘s scope is only within the __init__ function, so it will be undefined. You’d have to use self.reports instead of reports.

    As for your final question, your structure won’t really allow you to do this nicely. I would create a third class to handle employees and managers:

    class Business(object):
      def __init__(self, name):
        self.name = name
        self.employees = []
        self.managers = []
    
      def employee_names(self);
        return [employee.name for employee in self.employees]
    

    You’d have to add employees to the business by appending them to the appropriate list objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to select an H1 element which is the second-child in its group
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.