Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

How to declare objects in OOP C++?

How to declare objects in OOP C++?

In this tutorial, we will learn about the following;

How to declare an object in OOP C++?

Syntax to declare objects

Serial #Code
1int main()
2{
3furniture f;
4f.show_price();
5}

Line 1 and 2: We are starting the main function

Line 3: furniture is the name of class and f is the object of class furniture

Line 4: f is class name and . is used to access the function from a class and show_price() is the function name.

Line 5: Ending of the main function.

Program:

Serial#Code
1#include<iostream>
2using namespace std;
3class furniture
4
5private:
6 int price=8;
7 public:
8 int show_price() 
9
10cout<<“show price=”<<endl<<price; 
11}
12};
13int main()
14{
15 furniture f; 
16f.show_price();
17}

 

Fazal Rehman Shamil Click Here to Know More
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325
Dear Professors and Resarchers!You are welome to Cite these tutorials in your research or slides etc. Please don't forget to mention the reference of website. Copy Paste of text is strcitly forbidden. Images can be reuse because images are protected with watermark.

Leave a Reply

Your email address will not be published. Required fields are marked *