
406 Fundamentals of Computer Programming and IT
int qty;
}; // end of
class
int main ()
{
clrscr();
item one; // object declaration
one.codeno=123; // member initialization
one.price=123.45;
one.qty=150;
}
As soon as the above program is compiled, the compiler will display following error messages:
‘item::codeno’ is not accessible
‘item::prize’ is not accessible
‘item::qty’ is not accessible
‘item::codeno’ is not accessible
‘item::prize’ is not accessible
From the above discussion, we noticed that by default (without applying public or private keyword)
the class members are private (not accessible) whereas the struct members are public (accessible). ...