I am doing homework in C# in which I am implementing the abstract class of Account then I derived two classes form Account named as Saving Account and Checking Account and override some methods in derived classes. Now my problem statement says
Only Instantiate SavingAccount and CheckingAccount Through a reference of Account
Now I am unable to write the code of this because I know the simple object creation but I don’t know how to create an object through the reference of an object. Please tell me some syntax. Thanx
The idea is that an identifier can be the base type:
But when you instantiate it (or new up an instance), you can use any derived type
e.g.
EDIT I wanted to add that this is where OOP comes to life (read: “gets really fun!”). Now you can design an
interfaceor contract (such as with anAccountclass) – and program to the one design. But you may have different account types actually used. With the example I gave,accountwill continue to look like anAccount. Any ‘new’ methods or features inSavingsAccountwill not be immediately visiable to code using youraccountvariable. But that’s okay! You don’t want your code to be specifically tailored toSavingsAccount(in MOST cases), you want to instead design a flexibleAccountthat can represent the basic and common features of anyAccount.