locked
what are access modifiers for abstract class and its members ? RRS feed

  • Question

  • User-1682137340 posted

    hi i am new to c# can any one tell me , what are access modifiers for abstract class and its method ?

    i know they are public, protected ,internal, internal protected and  methods are also virtual , static

    am i right ?

    Thanks in advance 

    Saturday, September 20, 2014 11:39 AM

Answers

  • User281315223 posted

    i know they are public, protected ,internal, internal protected and  methods are also virtual , static am i right ?

    Essentially, there are a quite a few access modifiers within C#, some that relate strictly to scope and others that relate to how a particular method, property or class can be accessed. The following are strictly "access modifers" :

    • public - Access to this particular variable is not restricted.
    • protected - Access is limited to the containing class or types derived from the containing class.
    • internal - Access is limited to the current assembly.
    • protected internal - Access is limited to the current assembly or types derived from the containing class.
    • private - Access is limited to the containing type.

    These other keywords that you might come across that can be used similarly but often have different meanings or functions (such as assisting with inheritance and more) :

    • static - Declares a static member, which belongs to the type itself rather than to a specific object. Members decorated with static cannot be instantiated.
    • abstract - Indicates that a particular member, method or property will be overwritten by another class (and thus doesn't contain any implementation details)
    • virtual - Allows for a particular member, method, or property to be overwritten by another class (such as a derived class).

    You can find more information on all of these within the C# Modifers section of the MSDN documentation here.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 20, 2014 2:05 PM

All replies

  • User1293050055 posted

    C# have 5 access modifiers 

    Private public, protected ,internal, internal protected,

    and you can use above access modifiers to create abstracted method based on requirement.

    Private --Same class you use

    public-- Entire application

    Protected-- Parent class and child class 

    internal--Same Assembly(Name Space)

    Protected Internal--Same assembly and extended assembly

    Saturday, September 20, 2014 12:42 PM
  • User281315223 posted

    i know they are public, protected ,internal, internal protected and  methods are also virtual , static am i right ?

    Essentially, there are a quite a few access modifiers within C#, some that relate strictly to scope and others that relate to how a particular method, property or class can be accessed. The following are strictly "access modifers" :

    • public - Access to this particular variable is not restricted.
    • protected - Access is limited to the containing class or types derived from the containing class.
    • internal - Access is limited to the current assembly.
    • protected internal - Access is limited to the current assembly or types derived from the containing class.
    • private - Access is limited to the containing type.

    These other keywords that you might come across that can be used similarly but often have different meanings or functions (such as assisting with inheritance and more) :

    • static - Declares a static member, which belongs to the type itself rather than to a specific object. Members decorated with static cannot be instantiated.
    • abstract - Indicates that a particular member, method or property will be overwritten by another class (and thus doesn't contain any implementation details)
    • virtual - Allows for a particular member, method, or property to be overwritten by another class (such as a derived class).

    You can find more information on all of these within the C# Modifers section of the MSDN documentation here.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 20, 2014 2:05 PM