i have to create a fake DMV program that calculates annual fees, for commercial and private vehicles. Those two classes will be abstract and they will polymophism from a class named all vehicles.
My instructor wants only one object created the entire program(in main) but since my top 3 tier classes are abstract. I can't create an object with them i.e. vehicles = new vehicles();
so my question is how do i create only one object since they are abstract? If you have any questions feel free to ask, I might have not explained this well...
Your class structure will look something like:
and so on, for each class. In your
Main
method, you would create the instance based on input, but your actual variable would be declared as typeVehicle
. The actual calculation will take effect based on the instance that you create:Your instructor may want you to instantiate multiple objects through a reference to the abstract base class:
i.e. you have a single object reference (conveyance) that behaves polymorphically depending on the concrete type you've instantiated.
Maybe you are to make one object which represents the DMV, but the definition of that object includes instances of other objects.
You seem to be a bit confused. "All Vehicles" should be abstract. "Commercial Vehicle" and "Private Vehicle" should not be abstract, unless there are concrete subclasses of those two.
You may also not be understanding what your instructor means by "only one object", since that doesn't make sense.