Eating Coding Program Example using Single Level Inheritance in C++


The program defines two classes, Human and Coder, where Coder is derived from Human. The Human class has a public method eat() which prints the string "Eating..." to the console. The Coder class has a public method code() which prints the string "Coding..." to the console. In the main function, an object c1 of class Coder is created. The eat() and code() methods of c1 are then called.

Source Code

#include<iostream>
using namespace std;
class Human
{
   public:
    void eat()
    {
       cout<<"Eating..."<<endl;
    }
};
class Coder: public Human
{
   public:
    void code()
    {
       cout<<"Coding...";
    }
};
int main(void)
{
  Coder c1;
  c1.eat();
  c1.code();
  return 0;
}
To download raw file Click Here

Output

Eating...
Coding...

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples