Below is the code and I want to understand few things:
public class Test {
public 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 when we assign derived class object to base 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 Method1 which accept string argument. Somehow, I am unable to access this method. There are multiple classes exist which are derived from base abstract class. I want to keep things generic.