---
title: "Does base class object hold the derived class object?"  
description: "Does base class object hold the derived class object?"  
author: "Anonymous User"  
published: 2013-09-24  
updated: 2013-09-24  
canonical: https://www.mindstick.com/forum/1505/does-base-class-object-hold-the-derived-class-object  
category: "c#"  
tags: ["derived class object", "c#", "base class object", "mindstick", "object"]  
reading_time: 2 minutes  

---

# Does base class object hold the derived class object?

Below is the code and I want to understand few things:

public class Test {

[public void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) dosomething( ) {

Derived2 d2 = new Derived2 () ;

Base bobject = d2;

string str = "str" ;

bobject.Method1( str ); // I want to call Method1 of Derived1 class

}

}

public class Derived2 : Derived1 {

public void Method1( string s ) {

}

}

public class Derived1 : Base {

public override void Method1( double d ) {

}

public override void Method2( double d ) {

}

}

public abstract class Base {

public abstract void Method1( double d );

public abstract void Method2( double d );

}

I would like to know, what [exactly happens](https://yourviews.mindstick.com/view/81705/what-exactly-happens-when-a-patient-gets-into-coma) when we assign [derived class](https://answers.mindstick.com/qa/30686/what-is-a-base-class-and-derived-class) object to base [abstract class](https://www.mindstick.com/articles/1430/abstract-class) object. I know instantiating abstract class is not possible. In my case, I am deriving class Derived1 and assigning object of Derived2 class to base abstract class object. Now I want to access the Dervied2 [class method](https://www.mindstick.com/interview/22908/what-are-java-string-class-method) Method1 which accept string argument. Somehow, I am [unable to access](https://answers.mindstick.com/qa/50571/why-is-my-apple-iphone-8-unable-to-access-wi-fi-internet-and-how-to-fix-it) this method. There are [multiple classes](https://www.mindstick.com/forum/159384/how-can-i-select-an-element-with-multiple-classes-in-jquery) exist which are derived from base abstract class. I want to keep things generic.

## Replies

### Reply by Pravesh Singh

Hi Chintoo,

bobject is a type of Base which has two methods which accept a double, not a string (That method is defined in Derived2's implementation).

To do what you requrie you'd need to cast bobject to Derived2, like:

var d3 = bobject as Derived2;

d3.Method1("String");


---

Original Source: https://www.mindstick.com/forum/1505/does-base-class-object-hold-the-derived-class-object

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
