TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Thursday 4 June 2020

Class & Object In C++ | Class & Object Programming Language In C++ | Class & Object Notes | Class & Object In C++ In Hindi

Class & Object


In side of class we define the member function definitions they are two type s to declare the class &object.

          · Inside of class
     ·    
Outside of class


image of Class & Object In C++

Fig: Class & Object In C++

Definition of member function

Member functions of a class can be defined either outside the class definition or inside the class definition. In both the cases, the function body remains the same.


1.   Inside the Class: 

A member function of a class can also be defined inside the class. when a member function is defined inside the class, the class name and the scope resolution operator are not specified in the function header. The member functions defined inside a class definition are by default inline functions.


Syntax:

class MCA

{

private:

int a,b;

public:

void getdata();

void display()

{

cout<<a<<b;

}

};


2.   Outside the Class: 


Defining a member function outside a class requires the function declaration (function prototype) to be provided inside the class definition. The member function is declared inside the class like a normal function. This declaration informs the compiler that the function is a member of the class and that it has been defined outside the class. After a member function is declared inside the class, it must be defined (outside the class) in the program.


Syntax:

class MCA

{

private:

int a,b;

void getdata()

};

void MCA :: getdata()

{

cout<<”input two no”;

cin>>a>>b;

}


Program:

#include<iostream.h>

#include<conio.h>

class MCA

{

private:

int a,b,c,d;

public:

void getdata();

void display() //inside class

{

cout<<”d=”<<d;

}

};

void MCA :: getdata() //outside class

cout<<”input three value”;

cin>>a>>b>>c;

d=a*b*c;

}

void main()

{

MCA  x;

x.getdata();

x.getdisplay();

getch();

}


Output:

Input three value:

4

4

5

d=80

 


No comments:

Post a Comment