• Source
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. class Person
    6. {
    7. protected:
    8. string name;
    9. int age;
    10. };
    11.  
    12. class Student: public Person
    13. {
    14. private:
    15. string major;
    16. int year;
    17.  
    18. public:
    19.  
    20. string getMajor()
    21. {
    22. return major;
    23. }
    24.  
    25. void setMajor(string _major)
    26. {
    27. major = _major;
    28. }
    29. };
    30.  
    31. int main()
    32. {
    33. Student stu;
    34. stu.setMajor("Information Technology");
    35. cout << stu.getMajor();
    36. return 0;
    37. }