Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

The data members of a class by default are ?

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

user-image
Question added by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date Posted: 2016/10/21
Shahid Salam Khan
by Shahid Salam Khan , Software Engineer , Xavient Information Systems

By default the data members of a class are Private

anas alhashki
by 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
by 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