what is a class? Explain with an example.



what is a class? Explain with an example...

Answer / Amarjeet Kumar Paswan

A class in C++ is a user-defined data type that groups related variables and functions together. It encapsulates (hides) the implementation details from the users of the class, providing only the necessary interface to interact with the class objects. For example:nclass Car {n private:n string brand;n int year;n public:n void setBrand(string b) {n brand = b;n }n void setYear(int y) {n year = y;n }n string getBrand() {n return brand;n }n int getYear() {n return year;n }n};

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

Describe exception handling concept with an example?

1 Answers  


What do you mean by pure virtual functions in C++? Give an example?

1 Answers  


What does ios :: app do in c++?

1 Answers  


Which operator cannot overload?

1 Answers  


How do I run a program in notepad ++?

1 Answers  


What are references in c++?

1 Answers  


What is diamond problem in c++?

1 Answers  


What is the most common mistake on c++ and oo projects?

1 Answers  


Declare a class vehicle and make it an abstract data type.

1 Answers  


Which is not an ANSII C++ function a) sin() b) tmpnam() c) kbhit()

1 Answers  


What is the difference between map and hashmap in c++?

1 Answers  


Can we declare a base-class destructor as virtual?

1 Answers  


Categories