+ 1
What is difference between class and method in java
4 Answers
+ 3
bro.. both are totally different things.
yes there is relationship between them.
class is container for methods.
class is blueprint for objects.
methods shows the behavior of object.
-----------------------------
for ex.
String s = "Harish";
s=s.toUpperCase();
here 'String' is Claas.
'toUpperCase' is method.
+ 2
a class contains methos for execute the tasks that are required
0
class is user defined data type used as template to create one or more object. method is function defined within class is called method
ex
class Fact
{
public static void main(String args [])
{
int n=4;
long result=factorial(n);
System.out.println("factorial of given number"+result);
}
static long factorial(int n);
{
long facta=1;
while(n>0)
{
facta=facta*n;
n--;
}
return facta;
}
}
0
here class is Fact and method is factorial