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

  • Home
  • SEARCH
  • 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 8953923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:12:13+00:00 2026-06-15T14:12:13+00:00

I need your help to extend my base class, here is the similar structure

  • 0

I need your help to extend my base class, here is the similar structure i have.

    public class ShowRoomA
    {
            public audi AudiModelA { get; set; }
            public benz benzModelA { get; set; }
    }   
    public class audi
    {
            public string Name { get; set; }
            public string AC { get; set; }
            public string PowerStearing { get; set; }
    }
    public class benz
    {
            public string Name { get; set; }
            public string AC { get; set; }
            public string AirBag { get; set; }
            public string MusicSystem { get; set; }
    }
//My Implementation class like this
    class Main()
    {
      private void UpdateDetails()
      {
        ShowRoomA ojbMahi = new ShowRoomA();
        GetDetails( ojbMahi ); // this works fine
      }
      private void GetDetails(ShowRoomA objShowRoom)
      {
         objShowRoom;
         objShowRoom.audi = new audi();
         objShowRoom.audi.Name = "AUDIMODEL94CD698";
         objShowRoom.audi.AC = "6 TON";
         objShowRoom.audi.PowerStearing = "Electric";

         objShowRoom.benz= new benz();
         objShowRoom.benz.Name = "BENZMODEL34LCX";
         objShowRoom.benz.AC = "8 TON";
         objShowRoom.benz.AirBag = "Two (1+1)";
         objShowRoom.benz.MusicSystem = "Poineer 3500W";
      } 
    }
// Till this cool.
// Now I got requirement for ShowRoomB with replacement of old audi and benz with new models and new other brand cars also added.
// I don't want to modify GetDetails() method. by reusing this method additional logic i want to apply to my new extended model.
// Here I struck in designing my new model of ShowRoomB (base of ShowRoomA) ... I have tried some thing like... but not sure.

    public class audiModelB:audi
    {
            public string JetEngine { get; set; }
    }
    public class benzModelB:benz
    {
            public string JetEngine { get; set; }
    }
    public class ShowRoomB
    {
            public audiModelB AudiModelB { get; set; }
            public benzModelB benzModelB { get; set; }
    } 

// My new code to Implementation class like this
    class Main()
    {
      private void UpdateDetails()
      {
        ShowRoomB ojbNahi = new ShowRoomB();
        GetDetails( ojbNahi ); // this is NOT working! I know this object does not contain base class directly, still some what i want fill my new model with old properties. Kindly suggest here 
      }
    }

Can any one please give me solutions how to achieve my extending requirement for base class “ShowroomA”

Really appreciated your time and suggestions.

Thanks in advance,

  • 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-15T14:12:13+00:00Added an answer on June 15, 2026 at 2:12 pm

    The problem is here:

      private void GetDetails(ShowRoomA objShowRoom)
      {
         objShowRoom = new objShowRoom();  //<-----
    

    You’re not using the object you passed in – instead you’re creating a NEW object and using it. just remove

    objShowRoom = new objShowRoom();
    

    and fix this block:

         objShowRoom.benz= new benz();
         objShowRoom.audi.Name = "BENZMODEL34LCX";   //<--- should be objShowRoom.benz?
         objShowRoom.audi.AC = "8 TON";
         objShowRoom.audi.AirBag = "Two (1+1)";
         objShowRoom.audi.MusicSystem = "Poineer 3500W";
    

    and you should be fine.

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

Sidebar

Related Questions

I need your help. Say I have a code inside a for statement similar
Need your help!!! I have activity, where I get some data in JSON format
Need your help to get the max of CAP_PRICE based on certain criteria in
I need your help. I have made a really clean and simple example to
I have something to do for work and I need your help. We want
I need your help to solve a silly problem. I have 2 tables in
I need your help in JAVA (with some sample code if possible) regarding to
I need your help. I tried to play an audio file stored in Assets
I need your help with display of some comma separated enteries from my database.
I need your help with my script. What I'm trying t do is insert

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.