Explain the difference between public and static modifiers?



Explain the difference between public and static modifiers?..

Answer / Ashish Nag

In .NET, both Public and Static are access modifiers but they behave differently:nn- Public: It allows any part of the code (including other classes) to access a member. This is the default access level for members.n- Static: It indicates that a member belongs to a type rather than an instance of the type. Static members are shared among all instances and can be accessed without creating an instance.nnFor example:n```csharpnpublic class MyClass {n public int myField; // Public, per-instance fieldn static public void MyStaticMethod() { }n}nMyClass c1 = new MyClass();nc1.myField = 5;nMyClass.MyStaticMethod();n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Dot Net General Interview Questions

Explain garbage collection?

1 Answers  


What are virtual destructures?

1 Answers  


What is Ajax? How it is related to your project?

1 Answers   Wipro,


What is the difference between Server.Transfer and Response.Redirect?

4 Answers  


What is the use of ErrorProvider Control in .NET?

2 Answers  


Explain what do the terms “boxing” and “unboxing” mean?

1 Answers  


What is .net standard?

1 Answers  


Explain the difference between the while and for loop.

1 Answers  


What is a formatter in .net?

1 Answers  


Will it go to finally block if there is no exception happened?

1 Answers  


How viewstate is being formed and how it's stored on client in .net?

1 Answers  


What is meant by .Net framework?

1 Answers  


Categories