What is the difference between Virtual function and Pure Virtual function?

A virtual function makes its class a polymorphic base class. Derived classes can override virtual functions. Virtual functions called through base class pointers/references will be resolved at run-time. That is, the dynamic type of the object is used instead of its static type: Derived d;  Base& rb = d;  // if Base::f() is virtual and Derived overrides it, Derived::f() will be called  rb.f(); A pure virtual function is a virtual function whose declaration ends in =0: class Base {   // …   virtual void f() = 0;   // … A pure virtual function makes the class it is defined for abstract. Abstract classes cannot … Click here to continue reading.

Explain about abstraction?

Abstraction can also be achieved through composition. It solves a complex problem by defining only those classes which are relevant to the problem and not involving the whole complex code into play. The vehicle class described above is an example of abstraction. Abstraction is the process of representing simplified versions of real-world objects in your classes and objects. The car class does not describe every possible detail of a car, only the relevant parts for the system being developed. Modelling software around real-world objects can vastly reduce the time required to understand a solution and be able to develop and … Click here to continue reading.

What is an interface and what is an abstract class? Please, expand by examples of using both. Explain why.

Answers1: In a interface class, all methods are abstract without implementation where as in an abstract class some methods we can define concrete. In interface, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers. Interface and abstract class are basically a set of rules which u have to follow in case u r using them(inheriting them). Answers2: Abstract classes are closely related to interfaces. They are classes that cannot be instantiated, and are frequently either partially implemented, or not at all implemented. One key difference between abstract classes and interfaces is that a class may implement an … Click here to continue reading.