(45). OOPS CONCEPT BY LOVE BABAR. - anishsingh90/Data_Structure_And_Algorithm_In_Cpp_github.io GitHub Wiki

/* //OPPS CODE

#include <bits/stdc++.h> using namespace std;

class Hero{

int health;

};

int main(){

Hero h1; //creating object
cout << "size is: " << sizeof(h1) <<endl;
return 0;

} /* OUTPUT: size is: 4 */

/* //HOW TO INCLUDE CLASS IN HEADER FILE #include <bits/stdc++.h> #include "Hero.cpp" using namespace std;

int main(){ Hero h1;

cout << "size is: " << sizeof(h1) << endl;

return 0;

}

/* OUTPUT: size is: 4 */

/* //HOW TO ACCESS PROPERTY OF A CLASS #include <bits/stdc++.h> using namespace std;

class Hero{ public: int health;

private: char level;

void print(){
	cout << level << endl;
	}

};

int main(){

Hero h1; //creating object
cout << "heath is : " << h1.health << endl;
return 0;

}

/* OUTPUT: heath is : 0 */

/* //NEXT CODE #include <bits/stdc++.h> using namespace std;

class Hero{ public: int health; char level; };

int main(){

Hero h1; //creating object

h1.health = 70;
h1.level = 'A';

cout << "heath is : " << h1.health << endl;
cout << "level is: "  << h1.level << endl;
return 0;

}

/* OUTPUT: heath is : 70 level is: A */