web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

What is the default access control for class,data member and methods?

(0) ShareShare
ReportReport
Posted on by 1,552

By default is the class name public, private or protected?

what about the data members? and what about the methods?

 

class test   // by default is the class public,protected or private?
{
    int x =1;  // by default is x public,protected or private?
    
    int getX() // by default is the method public,protected or private
    {
        return x;
    }
}

I have the same question (0)
  • Blue Wang Profile Picture
    Microsoft Employee on at

    Hi Junior AX,

    All classes are public. If you remove the public modifier, the system still treats the class as public. You can specify other modifiers on the class declaration, such as final and extends.

    Instance variables are protected by default.

    More details:

    docs.microsoft.com/.../xpp-classes-methods

  • junior AX Profile Picture
    1,552 on at

    Thanks alot. But how about the method, what is it by default?

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,095 on at

    Hi Junior AX,

    Classes and methods are public by default. And global variables are protected by default.

    You can easily check it if you create your class and try to access class, method, and variable from another class.

  • junior AX Profile Picture
    1,552 on at

    Are variables inside the method protected by default as well like global ones?

  • Sergei Minozhenko Profile Picture
    23,095 on at

    Hi JuniorAX

    Variables declared inside the method can be accessed only within this method. Class variables (declared in ClassDeclaration) by default have a protected level.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans