A Methods Meaning

Hello, how are you doing? well i am fine indeed.On my last post we talked about class in programming, today we’ll talk about Methods because methods are one of the most important chunk of code inside a class(check out my last post about Classes). First I apologize if there is any mistake, any help or knowledge would be nice. Lets be done with the chit-chat and lets begin.

Methods… hmmm… methods, I wonder what it is, and what does it have to do with classes and objects. To get the answer let’s take a look at methods definion? well here it is
: a methods is a particular form of procedure  for accomplishing or approaching something, especially a systematic or established one.


You might wonder, what the heck does that suppose to mean? well… first… you’re tricked, this is not the real definition of methods in programming, this is a methods definition in general (haha!). I feel bad doing this, so I’ll just give you the definition of methods in programming, and here it is : A method in OOP is a programmed procedure that is defined as a part of a class and will be included in any object in that class.

How to call or execute a method? that is easy, well it took me some time to understand it but you will to eventually, here is how to call a method : 

Let’s take a look at an example of a methods :

/** the snippet returns the minimum between two numbers */ public static int minFunction(int n1, int n2) {
      int min;
      if (n1 > n2) min = n2;
      else min = n1; 
      return min; 
}

 There are actually two ways in which a method is called i.e. method returns a value or returning nothing (no return value). The process of method calling is simple. When a program invokes a method, the program control gets transferred to the called method. This called method then returns control to the caller in two conditions, when: 

  • return statement is executed.
  • reaches the method ending closing brace.

Easy right? you’ll get yourself better at it within time and within a lot of practicing. 

How about now? feeling better understanding this? well I hope you do, if you’re feeling better… let’s get to one of the most important method capabilities that is provided is methods overriding. The same name (e.g., area) can be used for multiple different kinds of classes. This allows the sending objects to invoke behaviors and to delegate the implementation of those behaviors to the receiving object. Methods inside Java programming will set the behaviour of the class object. For example, an object can send an area message to another object and the appropriate formula’s that is created will be invoked whether the receiving object is a rectangle, circle, triangle, or something else etc…
 
 Conclusions

  • A methods is a particular form of procedure  for accomplishing or approaching something, especially a systematic or established one. (In General).

  • A method in OOP is a programmed procedure that is defined as a part of a class and will be included in any object in that class.
  • This called method then returns control to the caller in two conditions, when: 
    • return statement is executed.
    • reaches the method ending closing brace. 

 

2 thoughts on “A Methods Meaning”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.