user37979
0
Q:

what are method in java

public static void main(String[] args)
{
	int length=getLength();
  	System.out.println("Your length is: "+length);
}
//methods are outside of main method
public static int getLength()
{
	int length=5;
  	return length;
}
5
public class MyClass {
  private int value = 10;
  // getter method
  public int getValue() {
    return value;
  }
  // setter method
  public void setValue(int value) {
    this.value = value;
  }
}
3
public int addNum(int num1, int num2) {
  total = num1 + num2;
  System.out.println("Total: " + total);
}
0
Static methods: A static method is a method that can be called and executed without creating an object
Instance methods: These methods act upon the instance variables of a class
Factory methods: A factory method is a method that returns an object to the class to which it belong
0
Method is a collection of statements
which returns a value upon its execution
Method have a return and the method's name may or not be same as the class
name.
Method is invoked explicitly.
Method is not provided by compiler in any case.
Methods are inherited by child classes.
0
Method is a collection of statements
which returns a value upon its execution.
  Method have a return and the method's name may or not be same as the class
name.
Method is invoked explicitly.
Method is not provided by compiler in any case.
Methods are inherited by child classes.
0

New to Communities?

Join the community