Advertisement
AlaminSakib

Classes in C++

Dec 24th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Geeks
  5. {
  6. public:
  7.     int i;
  8.     string name;
  9.  
  10.     // Default constructor
  11.     Geeks()
  12.     {
  13.         i = -1;
  14.     }
  15.  
  16.     // Parametrized constructor
  17.     Geeks(int num)
  18.     {
  19.         i = num;
  20.     }
  21.  
  22.     //inside class definition of method
  23.     void print_name()
  24.     {
  25.         cout << name;
  26.     }
  27. };
  28.  
  29. //class a derived from parent class b and c
  30. //class a : public b, public c
  31.  
  32. //outside class definition of method
  33. void Geeks::print_number()
  34. {
  35.     cout << i;
  36. }
  37.  
  38. //Henlo inherits the class Geeks. Henlo is child while Geeks is parent.
  39.  
  40. class Henlo : public Geeks
  41. {
  42.  
  43.  
  44. };
  45.  
  46. int main()
  47. {
  48.     Geeks g;
  49.     cout << g.print_name() << endl;
  50.     cout << g.name();
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement