Add two number using class and object in C++ by R4R Team

Example-
n1=10
n2=20
Sum is: 30

program-

#include < iostream>
using namespace std;
class myclass
{
public:
int n=10;
int sum(int a,int b)
{
cout<<"Sum is: "<< a+b;
}
};
int main()
{
myclass obj;
//sum of 3 and 4 using class and object
obj.sum(3,4);
return 0;
}


output-

Sum is: 7




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!