Professional Documents
Culture Documents
#include<iostream>
class Base
{
public:
virtual void foo() =0;
};
class late: public Base
{ public:
void foo() { std::cout<<"Derived"; } //Needed, its mandetory
};
int main()
{
Base *b = new late();
b->foo();
b = new late1();
b->foo();
Canine c;
//Its ok cause its an ref and be used by sub class
c = new Dog();
c = new Canine(); // Now this is serious trouble
c.roam();
}
Virtual Function
Inheritable method implementations (in other words, methods with actual body) are
good thing to put in a superclass that makes sense but in the abstract class you
cannot use anything. So by using method in place of class you can come up with
some generic code.
Definitions
Examples
Syntex
Syntax:
abstract class:
public class Apple extends Food { }
interface:
public class Person implements Student,
Athlete, Chef { }
Interface