answersLogoWhite

0


Best Answer

C++ does not have a built-in kilometre class. If you have such a class, it was provided for you by a third party. However, your IDE should be able to show you the members, including private members. I'd imagine such a class would have a private float or double member to store the actual number of kilometres it represents, and perhaps some public methods to convert the number to other formats, such as millimetres, centimetres, miles, yards, inches, etc.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the private data members of kilometer class in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How does a class in c plus plus enforce data encapsulation?

Data encapsulation is enforced by restricting access to the class members. Access can be specified on a per-member basis, defaulting to private access for a class and public access for a struct. Private members are accessible to class members and to friends of the class. Protected members are the same as private members but are also accessible to derived class members. Public members are fully-accessible. Data members are typically declared private while interfaces are typically declared public or protected.


Can Static data members be declared either in the private or public section of class declaration?

Yes. Static members can be private or public. (Or protected.)


In ANSI C you can hide data by using private access specifier Justify?

One can always declare a datatype as static which will limit the scope to the file only. this way data hiding can be achived. For more clearance on the same please refer 'the C programming language'. Data hiding means only relevant data is visible to the user and all the background information is hidden from the user. In c++, the variables are named as data members and these can be hidden with the help of private access specifier. In procedural languages, variables(global variables) are free to flow from functions to functions and hence they were not secured. But in C++, only the class in which the data members are being declared can access them by using private specifier. As, the data members and also member functions of a class cannot be accessed outside the class if they have private access so, they get hidden from the user and hence the data hiding is achieved. Also in inheritance when we derive a class from the base class then the derived class cannot access the private members of the base class. In addition, if a class is derived from another class privately i.e. for example syntax : class B : private A , is used then all the public and protected members (not private) becomes private to class B and cannot be accessed outside the class B, even by using the object of class B. Hence, data hiding is achieved in C++ through private access specifier.


Difference between structure and class?

Structure members are public by default while class members are private by default. Classes encapsulate the data and the methods that operate upon that data into a discrete package (an object), exposing only as much or as little interface as is required by the class itself, to ensure the data remains in a valid state at all times. Structures have no such protection.


Can you access in drive class from base class private data?

Base class should no knowledge about derived classes. The "private" modifier on a data member means private to the class which defined it. Base class cannot directly reference/access the private data member of the derived class, and the derived classes cannot access the private data member defined in the base class. Either way the accessing the private data member should be done via properties or getters

Related questions

How does a class in c plus plus enforce data encapsulation?

Data encapsulation is enforced by restricting access to the class members. Access can be specified on a per-member basis, defaulting to private access for a class and public access for a struct. Private members are accessible to class members and to friends of the class. Protected members are the same as private members but are also accessible to derived class members. Public members are fully-accessible. Data members are typically declared private while interfaces are typically declared public or protected.


Why private data members or functions are not inherited?

Because that's what private means. Private data members or functions are intended to be usable only in the base class, and the inheriting class can only access protected or public members or functions.


Can Static data members be declared either in the private or public section of class declaration?

Yes. Static members can be private or public. (Or protected.)


When class will be used and when structure will be used?

In class default members are private and in structure default members are public ,When ever you want to hide data from outside functions then you can use class.But in ANSI C we can hide data by using private access specifier.


In ANSI C you can hide data by using private access specifier Justify?

One can always declare a datatype as static which will limit the scope to the file only. this way data hiding can be achived. For more clearance on the same please refer 'the C programming language'. Data hiding means only relevant data is visible to the user and all the background information is hidden from the user. In c++, the variables are named as data members and these can be hidden with the help of private access specifier. In procedural languages, variables(global variables) are free to flow from functions to functions and hence they were not secured. But in C++, only the class in which the data members are being declared can access them by using private specifier. As, the data members and also member functions of a class cannot be accessed outside the class if they have private access so, they get hidden from the user and hence the data hiding is achieved. Also in inheritance when we derive a class from the base class then the derived class cannot access the private members of the base class. In addition, if a class is derived from another class privately i.e. for example syntax : class B : private A , is used then all the public and protected members (not private) becomes private to class B and cannot be accessed outside the class B, even by using the object of class B. Hence, data hiding is achieved in C++ through private access specifier.


Difference between structure and class?

Structure members are public by default while class members are private by default. Classes encapsulate the data and the methods that operate upon that data into a discrete package (an object), exposing only as much or as little interface as is required by the class itself, to ensure the data remains in a valid state at all times. Structures have no such protection.


Do the memory will be created for both private and public data members if the object is created for a class in c plus plus?

Yes.


Can you access in drive class from base class private data?

Base class should no knowledge about derived classes. The "private" modifier on a data member means private to the class which defined it. Base class cannot directly reference/access the private data member of the derived class, and the derived classes cannot access the private data member defined in the base class. Either way the accessing the private data member should be done via properties or getters


Can you return a reference to public data member?

Yes, but since it is public there is no need to; any code outwith the class can access a public data member directly. If it were a private data member, then returning by reference would defeat the point of making it a private data member in the first place; you might as well make it public. Private data members should always be returned by value, never by reference and never by pointer, and data members should only be declared public if they are not critical to the internal operation of the class.


Difference friend and public access modifier?

In C++, a friend function or friend class can grant access to its private data members to other classes. The public member allows any class to access that data.


What is a static data linkage?

Static data members of a class in namespace scope have external linkage. Static data members follow the usual class access rules, except that they can be initialized in file scope. Static data members and their initializers can access other static private and protected members of their class. The initializer for a static data member is in the scope of the class declaring the member. A static data member can be of any type except for void or void qualified with const or volatile. The declaration of a static data member in the member list of a class is not a definition. The definition of a static data member is equivalent to an external variable definition. You must define the static member outside of the class declaration in namespace scope.


What is Friend class How is it different from Abstract class?

Friend class is one which has been declared so (as a friend) inside other class to make it access the private members of the class which has extended it's friendship.For Example,class A{private:.......public:..............friend class B;};class B{.....................};As in the above code snippet, class A has extended it's friendship to class B by declaring B as it's friend inside it's area.Since the Class B has became a friend of A, B can directly access all the private members of A. But the reverse is not possible.Where as an abstract class is a one, which doesn't represent any particular object in nature. Instead they use give as abstract look of an object.For instance,When we say TATA Indca, Lancer, Ford Icon, Toyota Innova they are different car models. Each of them having their own properties and features, but all of them are Cars. So here, Car is an abstract class where as the others are concrete classes.