public data field : Public « Class « C++






public data field

  
#include <iostream>
using namespace std;
class Base 
{
 public:
   Base(void) { cout << "Base class constructor\n"; };
   int data; 
};

class Derived:public Base 
{
 public:
   Derived(void): Base() 
    { cout << "Derived class constructor\n"; };
};

int main(void)
 {
   Derived object;
   object.data = 5;
   cout << object.data << endl;
 }
  
    
  








Related examples in the same category

1.Illustrates the use of a public variableIllustrates the use of a public variable
2.Assign the public object member address to a pointerAssign the public object member address to a pointer
3.public class extending
4.field in struct is public by default
5.Class with only public fields and methods
6.Virtual public inheritance
7.public inheritance from three parent classes