locked
C#- Default access modifier of Abstract Class. RRS feed

  • Question

  • User2017388348 posted

    Hi All,

    A class having an Internal and Interface having Public default access modifier but what is the default access modifier of Abstract Class.

    Thanks.

    Thursday, June 21, 2018 7:28 PM

Answers

  • User-821857111 posted

    OK, Then what is default access modifier of Abstract Class?
    Internal.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 25, 2018 9:09 AM

All replies

  • User303363814 posted

    An abstract class is a class.  It has the same default access.

    BUT … if it is not obvious to you then it may not be obvious to people reading your code either.  Take the time and write the word internal and then you know, anyone reading the code knows and your code maintainers know without having to waste any time.

    Always imagine that the people maintaining your code are axe murderers and they know where you live!  Make their life easy.

    Friday, June 22, 2018 12:42 AM
  • User303363814 posted

    … and … if the code maintainer is you then be especially nice to yourself!

    Friday, June 22, 2018 12:43 AM
  • User36583972 posted


    Hi raushankarn,

    As the PaulTheSmith said, An abstract class is a class. It has the same default access.

    The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. 

    The following articles for your reference.

    Access Modifiers (C# Programming Guide):
    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers

    Abstract and Sealed Classes and Class Members (C# Programming Guide):
    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/abstract-and-sealed-classes-and-class-members

    Best Regards,

    Yong Lu

    Friday, June 22, 2018 4:03 AM
  • User2017388348 posted

    Hi PaulTheSmith and Yohann Lu,

    Thanks for your response.

    As the PaulTheSmith and Yohann said, An abstract class is a class. It has the same default access.

    you mean to say default access modifier of Abstract class is Abstract. I am correct.

    Note: I had written something is wrong in my question i.e. default access modifier of the interface is public that's wrong.

    According to the Microsoft classes and structs, interfaces default to internal access.

    Access Modifiers (C# Programming Guide):

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers

    Friday, June 22, 2018 6:40 AM
  • User303363814 posted

    'abstract' is not an access modifier.  In your OP you said 'internal'.

    Monday, June 25, 2018 2:00 AM
  • User2017388348 posted

    @Paul-abstract is not an access modifier.  In your OP you said 'internal'.

    OK, Then what is default access modifier of Abstract Class?

      

    Monday, June 25, 2018 5:21 AM
  • User-821857111 posted

    OK, Then what is default access modifier of Abstract Class?
    Internal.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 25, 2018 9:09 AM
  • User303363814 posted

    Seriously, if it going to take five days to work out which access is implied when it is omitted then DO NOT rely on the default.  You can save yourself five full days by just writing the actual access that you want.  Spend 3 seconds - save five days!

    And … you also save anyone else reading your code that time as well.

    Tuesday, June 26, 2018 12:18 AM