How can I cast objects that don't inherit each other?

Viewed 1113

I have 2 different classes with different fields and a class which has all the fields of both classes. Is there any way to cast the object in to two separate objects?

class A{
    private int a;
    private int b;
}

class B{ 
    private int a;
    private int b;
}

If object D have all the properties of A and B classes, Is there any way to cast them separately?

2 Answers
Related