Answers for "java method syntax"

3

Methods in java

public class MethodExample
{
    public static void main(String args[])
    {
       printHi();
       int add = Addition(8, 3);
       System.out.println(add);
    }
    public static void printHi()
    {
       // This method has no return value
       System.out.println("Hi!");
    }
    public static int Addition(int a, int b)
    {
       // This method has a return value
       return a + b;
    }
}
Posted by: Guest on October-18-2021
2

what are method in java

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
Posted by: Guest on October-01-2020
10

java method

public class Main {
  public static void main(String args[]) {
    SayHi();
    
    int sum = AddNums(5, 6);
    System.out.println(sum);
  }
  
  public static void SayHi() { //This method has no return value
    System.out.println("Hi!");
  }
  
  public static int AddNums(int a, int b) { //This method has a return value
    return a + b;
}
Posted by: Guest on December-20-2019
3

java methods

public class MyClass {
  static int myMethod(int x) {
    return 5 + x;
  }

  public static void main(String[] args) {
    System.out.println(myMethod(3));
  }
}
// Returns 8
Posted by: Guest on June-02-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language