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

Notifications

Announcements

No record found.

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
    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,093 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,093 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans