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

September 25, 2013 0 Comments

“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

}

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments: