What are the access-specifiers available in c#?

Answers were Sorted based on User's Feedback



What are the access-specifiers available in c#?..

Answer / soundararajan rajendran

Public
Protected
Internal(Known as "Friend" in C++)
Private
Protected or Internal

Public:
Any one can access the member functions and variables.
Protected:
Only child classes or classes that derive from this can
access.
Internal:
Classes within the same assembly can access but not by
child classes.
Private:
Accessible within the same class only.
Protected or Internal:
Member functions and variables can be accessed from the
classes which are in the same assembly Or can be accessed
from the the child classes.

Is This Answer Correct ?    19 Yes 7 No

What are the access-specifiers available in c#?..

Answer / kumar vishwajit

1)Public: if we declare any member as public then it can be
accessed from anywhere.
ex: Class Myclass1
{
public int x;
public int y;
}
Class Myclass2
{
public static void main()
{
Myclass1 mc=new Myclass1();
//direct accessing public member
mc.x=10;
mc.y=15;
console.writeline(mc.x,mc.y);
}
}
2)Private: Private members are accessible only within the
body of the class or the struct in which they are declared.
ex:
class Employee
{
public string name = "Jeet";
double salary = 100.00; // private access by default
public double AccessSalary() {
return salary;
}
}

class MainClass
{
public static void Main()
{
Employee e = new Employee();

// Accessing the public field:
string n = e.name;

// Accessing the private field:
double s = e.AccessSalary();
}
}
double s = e.salary; //can not be accessed due to private
lavel....

3)Protected: A protected member is accessible from within
the class in which it is declared, and from within any class
derived from the class that declared this member.

ex:class A
{
protected int x = 123;
}

class B : A
{
void F()
{
A a = new A();
B b = new B();
a.x = 10; // Error
b.x = 10; // OK
}
}
//a.x =10 generates an error because A is not derived from B.
4)internal - The member can only be accessed from type it
originates from or other types in the same assembly
5)it's similar to Protected access
specifier, it also allows a class to hide its member
variables and member function to be accessed from other
class objects and function, excepts child class, within the
application. used while implementing inheritance.

Is This Answer Correct ?    12 Yes 6 No

What are the access-specifiers available in c#?..

Answer / anas

An access specifier determines how other parts of a program
can access a class member.

Member access is controled by five access specifiers:

1. public,
2. private,
3. protected,
4. internal.
5. protected internal

1. public member can be accessed by any other code in
your program.
2. Main() is declared as public because it will be called
by code outside of its class (the operating system).
3. private member can be accessed only by other members
of its class.
4. A protected member is public within a class hierarchy,
but private outside that hierarchy.
5. A protected member is created by using the protected
access modifier.
6. The internal modifier declares that a member is known
throughout all files in an assembly, but unknown outside
that assembly.
7. The protected internal access level can be given only
to class members.
8. A member declared with protected internal access is
accessible within its own assembly or to derived types.

Is This Answer Correct ?    9 Yes 4 No

What are the access-specifiers available in c#?..

Answer / rajendra

In C# .net the access specifiers are:
1.private
2.Internal
3.protected
4.protected Internal
5.Public

In VB.net the access specifiers are:
1.Private
2.Friend
3.Protected
4.Protected Friend
5.Public

Is This Answer Correct ?    8 Yes 5 No

What are the access-specifiers available in c#?..

Answer / susanta sahoo

private-accessible with in the class.
protected-accessible with in the class and its child class only in the same project.
internal-access to its child and non child class with in a project.
protected internal-accessible to its child & non child within
the same project(internal inside the project) & accessible to its child class only when a reference is made(protected outside project).
public -accessible to any object.

Is This Answer Correct ?    3 Yes 0 No

What are the access-specifiers available in c#?..

Answer / angel

BS Bank Inc wants to add some additional features in the application. The company asks FIT
technologies for the following additions: [15 Marks]
? BS Bank Inc. needs to add modules to provide the following services:
a. Online share and mutual funds trading 
b. General insurance for health, car, and travel [10 Marks]
BS Bank Inc. should be able to provide other services like bill payments, mobile recharge. [5
Marks] [Use static variables and static function to implement this.]

Is This Answer Correct ?    2 Yes 0 No

What are the access-specifiers available in c#?..

Answer / srinu

private --> the members can access in the same class of
same project

internal --> the members can access from the same project,
but any class

protected --> the child class members of the class can
access the members either in same project or another
project.

protected internal --> dual scope( internal + protected ).

pubic -->access from any where.

Is This Answer Correct ?    4 Yes 3 No

What are the access-specifiers available in c#?..

Answer / kedarnath

1.Private:Members declared as private under a class or structure can’t be accessed outside of the type in which they are defined and moreover their scope is private only. Types cannot be declared as private where it is applicable only to members.
NOTE: Interfaces cannot contain any private members in them and default scope for interface members is public.
2.Protected:Members declared as protected under a class can be accessed only from itself or its child class, a non child class can’t consume them. Type can’t be declared as protected also. It applies only to members.
3.Internal:Members and types that are declared as internal are also accessible only within the project both for child and non child. The default scope for any type in C# is internal only.
4.Protected Internal:Members declared as protected internal enjoy dual scope i.e with in the project they behave as internal providing access to everyone in the project, outside the project they change to protected and still provide access to their corresponding child classes.
Types are also declared as protected internal only.
5.Public:A type or member of a type if declared as public will be global in scope which can be accessed from anywhere.

Is This Answer Correct ?    1 Yes 0 No

What are the access-specifiers available in c#?..

Answer / faiyazul islam

public - allow to access member functions and member
variable of a class from other class that can be inside or
outside of namespace collection.

private - only allow to access member functions and member
variable of a class within the same class.

protected- allow to access member functions and member
variable of a class from within same class and child classes
that can be inside or outside the namespace collection.

internal - allow to access member functions and member
variable of a class from within same class and class within
the inside namespace collection.

internal protected - allow to access member functions and
member variable of a class from within same class and and
child class within the inside namespace.

Is This Answer Correct ?    0 Yes 0 No

What are the access-specifiers available in c#?..

Answer / rama thakur

public
private
protected
internal
protected internal

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

Can you prevent your class from being inherited and becoming a base class for some other classes?

5 Answers  


How do I download a program to my desktop?

0 Answers  


how can we pass parameters to a user control using delegates ?

1 Answers   IBM,


What is dictionary and hashtable in c#?

0 Answers  


What exactly happens when we debug and build the program?

0 Answers  






What is expandoobject in c#?

0 Answers  


Can a structure inherit a class.

3 Answers   Infosys, Synechron,


Which is better javascript or c#?

0 Answers  


what are delegates? How you used then in your project?

10 Answers   Hawk Eye, IndiaTimes, Kanbay,


What is the real use of interface in c#?

0 Answers  


Why do we need constructor in c#?

0 Answers  


What is a int in c#?

0 Answers  


Categories