Instance of class cann’t access member of the class within the class

“Clubing data member and member function known as class.”

lets take an Example
Class A
{
Data member;
Member function;
}

If we create instance of the class in other class, that instance cannot access member of the class

lets take an Example

Class B
{
A  obj=new A();
A.Datamember;  // Error  instance member cann’t access datamember within the class
}

Solution :
Every executable statementmust be in a definition block( inside a function , constructor)
Class B
{
A obj =new A();
Public B()
{
Obj.DataMember=value; // you can access the datamember

}
Instance of class cann’t access member of the class within the class Instance of class cann’t access member of the class within the class Reviewed by Jacob Lefore on September 25, 2013 Rating: 5

No comments