Answers for "method function difference"

4

difference between function and method

#inclue<iostream>
using namespace std; // Bad Practice!!!

/* 
	*******IF YOU DONT KNOW OOP(OBJECT ORIENTED PROGRAMMING) FIRST LEARN IT THEN COME HERE
	AGAIN*******

	Simply, Method = Function.

	But Difference is that

	We call a Function A 'Method' When That Function Is Written Inside a Class(a blueprint)
	But if that Function is not Declared inside a class body then we call it 'Function'
*/

//Example:

class Employee
{
  public:
  	void getData(void); // This Is A 'METHOD'
}

void Employee :: getData(void) // This is Also A Method Because It Is Pointing Towards The GetData Function In Employee Class.
{
  cout<<"GET DATA!!!!!!"<<std::endl; // Good Practice (std::endl) use "std::"
}

int main() // This Is A Function, Cause It's Not Pointing Towards The Class As Well As Not Initialized Inside The Class Body
{
  
  cout<<"Hello"<<endl;
  
  return 0;
}

void DoSomethingGood(void) // This Is A Function As Well.
{
  
  if (2+2==5)
    return;
}
Posted by: Guest on July-21-2021
0

method function difference

A method, like a function, is a set of instructions that perform a task. The difference is that a method is associated with an object, while a function is not.
Posted by: Guest on July-01-2021

Code answers related to "method function difference"

Browse Popular Code Answers by Language