Question:
what is the difference between class and method?
Bhavani
2007-06-27 00:48:09 UTC
in programming
Eight answers:
xytose
2007-06-27 00:57:04 UTC
Quite a bit my friend.



A class is a block of code that encompasses many variables, structures, enumerations, methods and much more. Classes hold the biggest chunk of data. A practical example of a class would be a car engine. The car engine could have many properties (variables) and methods (functions). For example, it's variables could tell us how hot it is, or how hard it's working. Additionally it's functions can be to start up, or to generate work.



A method is an object-oriented term for function. It performs whatever the developer defined before they compiled it. A method could have many parameters and/or a return value. A practical example of that is like a copy machine that has papers as parameters and copied paper as the output return value.
2017-01-19 20:23:13 UTC
Difference Between Class And Method
rohit k
2007-06-27 00:53:39 UTC
A class is a set of objects that share a common structure and a common behavior; a single object is simply an instance of a class . A class is a specification of structure (instance variables),behavior(methods) and inheritance for objects.



Classes are important mechanism for classifying objects.The chief role of a class is to define the properties and procedures (state and behavior) and applicability of its instances.



A method or behavior of an object is defined by its class and typically can access the internal state of an object of the class to perform some operation.Methods encapsulate the behavior of the object,provide interface to the object and hide any of the internal structure and states maintained by the object.



As we know objects communicate by sending messages this is where the methods and functions differ.In a language like C or BASIC suppose we have to calculate the area of a circle .The subroutines will just call the function areaofcircle() by name and the parameters will be passed and the result will be obtained.



While in object oriented approach we instead of calling it by name will pass a message. The message will be sent by the main class to the more general method say area here and then from there to the more like triangle , rectangle , circle etc.

This is where the difference is between function and method.
2014-01-03 08:04:46 UTC
Here goes, as much for my benefit as anyone else's and this is designed to be imperfect but explanatory to people like me who have been confused for years.



Method: the "how to" for straightforward, repeatable programming code, like function or procedure, can be included in many Classes (think "programs") and can be passed info (parameters) and passes back info (return)



Example: 1. read_from_database(table name), 2.Write_to_database(table name), 3.Get_user_input_form



Class: a program (or template, they call it) that has its own code, variables, defaults, forms, arrays, etc., and may optionally include one or many Methods



Example: "subscribe, unsubscribe from distribution list"



Object: think of this as an instance or instantiation of the Class. Suddenly the "template" is real and its variables are populated.

---



Examples:



Methods:

show_Form

get username

get password

show banner

read from database

get user input

write to database



Class:

"subscribe, unsubscribe from distribution list"; which contains all the "glue" that holds and coordinates all the Methods" So far we're working on paper and screen, nothing is running yet and all we have created is a “template”.



Object:

Now we invoke the Object i.e. run the program or Class, and all the variables get populated and defaults default, and it is no longer a template, whether you're desk checking it by running through I/O examples or actually running the program.



This would explain why Class and Object tend to be used interchangeably, much as "database" and "instance" are used interchangeably, however the one (database) is shut down and the other (instance) is running version of the database, with memory allocated and so on.



In my mind, Class is the non-running, template or program, whereas Object would be the Class, alive and running with all its variables populated or defaulted, etc. Subtle difference.



I know there is more to it, but how far off the basics am I?
Venkat K
2007-06-27 01:03:41 UTC
If you are familier with progrmming terms.. here it is..



A Method - Is just like a function() in other Programming langauge.



A Class - Basically is a Object. The object contains group of methods and attributes through which you can access the object.



Example : Receiptionist is a Class



The Methods are - receivePeople()

provideInformationToPeople()

attendPhoneCalls()



Hope this givesyou idea.. Please update me if it is ok
triamburate
2007-06-27 01:01:37 UTC
if i remember correctly, classes are like pre-packaged modules complete with unique functions and variables only it could use. Any instance of a class could use the unique functions and variables it was provided with the "parent" class. For example, think of a class named "student". It has variables name, address, telephone number, strengths, weaknesses. Then, an invocation of class "student" occurred called, "John". class "John" will also have the same variables and methods which are unique to class "student", the parent class. A method on the other hand is similar to a function in C. It could be used by any other class or method and it has no unique properties.
A117
2007-06-27 00:52:25 UTC
a method is the interface of a class, describing how you can use the class.

a class contains methods and attributes.
shennalyn
2015-06-15 00:28:40 UTC
thanks


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...