Java Methods: Functions Inside Classes

Day - 3 : Methods in Java A method is a function written inside the class. Since Java is the object oriented programming language, we need to write the method inside same class. ● Calling a method : A method can be called by creating the object of the class in which the method exists followed by the method call. ● Void return type : When we don't want our method to return anything, we use void as the return type. ● Static Keyword: Static keyword is used to Associate a method of a given class with the class with the class rather than the object . Static method in a class is shared by all objects. ● Syntax : datatype name( ) { // method body; } ● Example : class java { static void add(int a, int b) { System.out.println("Sum = " + (a + b)); } public static void main(String[] args) { add(10, 20); } } #Java #CoreJava #Arrays #MultidimensionalArray #FullStackJava #LearningInPublic EchoBrains

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories