------------------------------------------------------------------------------------------------------------------
Please see simplified version of below program. First part of code declare several classes. Class A is simple class have one member method1. Class B and C both derived from A implement same member method1.
------------------------------------------------------------------------------------------------------------------
I have arrayA of type A in main, this store instance of B and C. See main in code where I want to call method1 of B and C how I call that.
Please see simplified version of below program. First part of code declare several classes. Class A is simple class have one member method1. Class B and C both derived from A implement same member method1.
------------------------------------------------------------------------------------------------------------------
I have arrayA of type A in main, this store instance of B and C. See main in code where I want to call method1 of B and C how I call that.
- Class A
- {
- method1()
- {
- console.write(" XYZ");
- }
- }
- Class B:A
- {
- new method1()
- {
- // some statement
- }
- }
- Class C:A
- {
- new method1()
- {
- // some code
- }
- }
- main()
- {
- arrayA.add(objB );
- arrayA.add(objC );
- foreach(A a in arrayA)
- {
- a.method1();
- }
- }
Comment