C++ interview questions

What is the difference between interface and super class?
AFAIK interface is build by pure virtual functions which are implemented in "real" code. "super class" as you mentioned is (?) a class containing functions which should be inherited by another class.

JUST for example:
animal is a generic class which can be used as a "mold" to being used classes such as cats, dogs, humans etc. -> interface

coordinates (yeah; x,y(,z)...) is a truly a thing which EVERYTHING has (also animals) and such does NOT need virtual functions since they act exactly same without touching each class separately. -> "super class"


NOTE! this is how i think how it is ;)
Last edited on
As eraggo said, an interface -- in the C++ class sense -- is a class with only pure virtual methods (no implemented method, no data members)

A super class = base class = parent class

As interfaces can't be instantiated on their own, they serve as super/base classes of a class which want to implement them. The derived class does all the actual work.

For example, if you want to implement a program which connects to all available types of database, you could define an interface IDatabase (some conventions use an I prefix for all interface classes)

Then you could implement a class that connects to a MySQL database, another that connects to a SQLite database, ... all of which derive from IDatabase. But the program would only ever care about the functions in IDatabase, rather than specifics of any particular SQL implementation.

If you functionality which is common to all types of database, it could be factored into a base class of MySQL, SQLite, ... Then you'd have

MySQLDatabase -> Database -> IDatabase 


Here Database is a super class of MySQLDatabase, and the interface IDatabase is a super class of Database.

In practice, Database is likely to be abstract. That is, it has some (but not all) pure virtual methods, and is likely to have data members.

Andy

P.S. All interfaces are abstract classes, but not vice vera.
Last edited on
Thankyou very much for the answer.
Hi,

Thanks very much for this comment. It help me to think about my ideals.

Tks again and pls keep posting.

If you want to get more materials that related to this topic, you can visit: http://interviewquestionsandanswers.biz/

Best regards.
Last edited on
Hi Hamburg
Thanks for your useful link.
Some site relating interview questions I found:
http://interviewquestionstoask.info
http://typicalinterviewquestions.info
http://jobinterviewquestions.biz
Hope this useful for the candidats.
Last edited on
Topic archived. No new replies allowed.