Is there any way to access private memebers of an object
from another object?

Answer Posted / rajesh

In C++ we can access private members of one class by the
object of another class,befor that we have to
make "friend"(keyword) the respective member of the first
class to the second class
for ex:
class A
{
private void display();
};

inherits: class B
{
friend void display();
};
Now we can acess the 'display' function using classB
object.We can only make friend to the immediate inherited
class and not to all classes under inheritance.

and in C# we have to create a property as first answer

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is c# a good programming language?

471


How can I use .NET components from COM programs?

487


Why use “using” in c#?

520


what is the purpose of using statement in c#

547


What is tpl in c#?

493






Can an int be negative c#?

581


Can a struct inherit from another struct or class in c#?

515


What is difference between private and protected in c#?

488


What is console readkey ()?

525


How do generics work in c#?

480


What is the difference between interface and inheritance in c#?

465


What is the difference between == and object.equals?

499


Is a games console a computer?

474


What are custom exceptions? Why do we need them?

517


can you create a function in c# which can accept varying number of arguments

591