MyClass.java:4: error: name has private access in Person myObj.name = "John"; ^ MyClass.java:5: error: name has private access in Person System.out.println(myObj.name); ^ 2 errors Instead, we use thegetName()and
To access a private attribute, use public "get" and "set" methods: Example #include <iostream> using namespace std; classEmployee { private: // Private attribute intsalary; public: // Setter voidsetSalary(ints) { salary = s; }