If one member of a class is private, all the members of that class must also be declared as private.
True or False?
PLEASE NOTE : FEEL FREE TO ASK ANY DOUBTS by COMMENTING
Question : If one member of a class is private, all the members of that class must also be declared as private.
Answer : False
:::::::::::::::::::::::::::::::::::::::::::: EXPLANATION ::::::::::::::::::::::::::::::::::::::::
we have 3 types of access modifiers
Every member has an access modifiers. It depends on how we access the members.
We have following members
If we want a member to use with in the class we can use any access modifier.
If we want to use a member outside class we use either of the access modifiers except private.
If we want to use a member from any where, we must use access modifier public.
Assigning access modifier is depends upon how we access the data from class.
It is not necessary to make all class members as private.
_________________________________________________________________
Dear Friend, Feel Free to Ask Any Doubts by Commenting. ASAP i'll respond when i'm available.
I'm on a critical Situation. Please Do Not Forget To Give A Thumbs UP +1. It will Helps me A Lot.
Thank YOU :-)
If one member of a class is private, all the members of that class must also...
Write a C++ program that has one base class named EMPLOYEE that has private members NAME, SALARY, YEAR_HIRED and one derived class named MANAGER that inherits from EMPLOYEE. MANAGER also has private member STAFF which is an array of strings. In the body of program, declare an object of each and enter data.
Overloading Design a UML diagram for a TimeClock class with the following private data members: • float days • float hours The class should also have the following public member methods: • Constructor with a default that sets the data values to 0 • getDays to return the private data member days • getHours to return the private data member hours • setDays to set the private data member days • setHours to set the private data member hours •...
C++ Question Modify the class by changing private members to protected members and viewing Account class as a base class. Define two derived classes Checking and RRSP. The Checking class has one additional private data: total(double). It has five public member functions: a constructor Checking (string n, string addr, double b, int p, double tot) (note you must call base constructor by using initialization list), double getTotal() to return total, void setTotal() to updata data, void withdraw(double w) which requires...
Write a class named Taxicab that has three private data members: one that holds the current x-coordinate, one that holds the current y-coordinate, and one that holds the odometer reading (the actual odometer distance driven by the Taxicab, not the Euclidean distance from its starting point). The class should have an init method that takes two parameters and uses them to initialize the coordinates, and also initializes the odometer to zero. The class should have get members for each data...
True /False 13. _There is only one copy of the class's member func- tions and that copy is shared among all the class's objects 14. Putting class definition in a separate file (e-g. head- er) makes it easy to reuse. 15. _A private data member of a class can usually be accessed from outside the class. 16. A member function of a class can call other private member functions of the same class. 17. _A destructor function can have parameters....
Members of a class that are declared private may be accessed a) only by methods of the class. b) only by methods of the class or friends of the class. c) only by methods of the class, subclasses of the class, or friends of the class. d) by any code.
in c++
Define and implement the class Employee with the following requirements: private data members string type name a. b. double type hourlyRate 2. public member functions a. default constructor that sets the data member name to blank"and hourlyRate to zero b. A constructor with parameters to initialize the private data members c. Set and get methods for all private data members d. A constant method weeklyPay() that receives a parameter representing the number of hours the employee worked per...
(Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables to 0. b)...
For the following code, which statement is not true? Class Point { private: double y; double z; public: double x; }; a.z is available to objects of type Point declared outside the class. b.x is available to objects of type Point declared outside the class. c.x, y, and z are called members variables of the class. d.The name of the class is Point. Given the code below, What is the most accurate description of AwesomeClass(AwesomeClass...
C++ Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [3pts]. The constructors and the set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception...