TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
48
12.2k
Derived class method without matching base class method?
Oct 9 2019 1:24 PM
I would like to have methods that are unique to a sub-class. Visual Studio doesn't like this and won't let me compile. Is it possible to have a method in a derived class without it being in the base? Consider the following pseudocode:
abstract
Class Vehicle
Vehicle()
Class Car : Vehicle
Car()
OpenTop(
bool
isConvertible)
Class Truck : Vehicle
Truck()
PullTrailer(
bool
hasTrailerHitch)
Main
Vehicle car =
new
Car();
Vehicle truck =
new
Truck();
car.OpenTop(
true
);
// It doesn't like this.
car.PullTrailer(
false
);
// Or this.
From the error it looks like the program expects both OpenTop and PullTrailer to appear in Vehicle, which I could, but I believe that I have been able to do something similar to this in past code, so I'm not sure what I'm missing. Must I declare the car and truck as:
Car car = new Car();
and
Truck truck = new Truck();
And if I do that, will it prevent me from using anything from Vehicle?
Reply
Answers (
1
)
show popup window when database date matches system date
C# code to start SQL Server (MySQLSERVER) Automatically