What is class in c++ with example?



What is class in c++ with example?..

Answer / Seema Sagar

A class in C++ is a blueprint for creating objects. It defines the data members (variables) and member functions (methods) that an object will have. Here's a simple example of a class representing a rectangle: `class Rectangle { private: int length; int width; public: void setLength(int l) { length = l; } void setWidth(int w) { width = w; } int getArea() { return length * width; } };`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What kind of jobs can I get with c++?

1 Answers  


Explain what is class definition in c++ ?

1 Answers  


Does dev c++ support c++ 11?

1 Answers  


What language does google use?

1 Answers  


Define precondition and post-condition to a member function?

1 Answers  


What is the use of static functions?

10 Answers   Symphony,


What is a local variable?

1 Answers  


What is the topic of the C++ FAQ list?

1 Answers  


Explain how to initialize a const member data.

1 Answers  


Describe private, protected and public – the differences and give examples.

1 Answers  


what is the size of a class which contains no member variables but has two objects??? is it 1 or 2??

4 Answers  


What is the object serialization?

1 Answers  


Categories