Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

The data members of a class by default are ?

a) protected,publicb) private,publicc) privated) public

user-image
Question ajoutée par Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date de publication: 2016/10/21
Shahid Salam Khan
par Shahid Salam Khan , Software Engineer , Xavient Information Systems

By default the data members of a class are Private

anas alhashki
par anas alhashki , Senior Full Stack Engineer , Industrial Motor Power Corporation

Private

Because it's better to be properly encapsulated and only open up the things that are needed, as opposed to having everything open by default and having to close it.

 

Amit Sharma
par Amit Sharma , Systems Analyst , TCS

1. Data members of a class are by default private.

2. A private function of a class can access a public function within the same class.

 

3. A member function of a class is by default private.

Eg.

public class Program

    {

        int i = 10;

        static void Main(string[] args)

        {

          

        }

    }

 

    public class Test : Program

    {

        public void M1()

        {

            // We are not able to access variable i because i is by default private.

        }

 

    }

Privately accessible data members

More Questions Like This