0
What's the difference between method and property
methods and properties
5 Réponses
+ 9
property is a value,
method is a callable function
+ 6
properties are your class members like
private int age;
private name;
Methods are used for getting and setting private field values
+ 6
ill try,
Public String name; < this is called a field.
Private int age; < this is also a field but has controlled access thorough using get and set.
As your having to access the private field via a method this method is called the property which has the get and set inside the methods body.
+ 2
Thanks D_Stark but I want know the the key difference between the two.
+ 1
let's understand with practical example
take class Human
class Human
{
// first we declare property of human
Int NoOfEar;
int NoOfHand;
int NoOfFingure;
// now declare method of human
Void Eat()
void Sleep ()
void Walk ()
}
so this the concept of property and methods.