Posted by Belajar Pemrograman
Program C++ Inheritance
#include<iostream>
using namespace std;
class induk
{
public:
int x,y;
void pesan()
{
cout<<"\n\nThis message is belong to class induk"<<endl;
cout<<"It's called by objek...."<<endl;
}
};
class anakan : public induk
{
public:
anakan()
{
x=100;y=10000;
}
};
int main()
{
induk parent; anakan anak;
parent.pesan();
anak.pesan();
cout<<"X= "<<anak.x<<endl;
cout<<"X= "<<parent.x<<endl;
system("pause");
}