-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprac1.cpp
More file actions
25 lines (23 loc) · 745 Bytes
/
prac1.cpp
File metadata and controls
25 lines (23 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>
using namespace std;
class fruit{
public:
string name;
string color;
};
int main(){
fruit apple;
apple.name="Apple";
apple.color="Green";
cout<<apple.name<<"-->"<<apple.color<<endl;
fruit *mango =new fruit(); // object creation using the new keyword,make sure to not use the dot operator while creating object with new keyword
mango->name = "Mango";
mango->color = "Yellow";
cout<<mango->name<<"-->"<<mango->color<<endl;
return 0;
}
// constructor are used to initialize an object and this is a function which is called whenever an object is created,it will have same name as class name
//Types of Constructor
//default constructor
//copy constructor
//paremetrized constructor