

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are Class/Static methods in Java?
The Class/Static methods are the methods that are called on the class itself, not on a specific object instance. The static modifier ensures implementation is the same across all the class instances. The class/static methods are called without instantiation means that static methods can only access other static members of the class. A few Java built-in static/class methods are Math.random(), System.gc(), Math.sqrt(), Math.random() and etc.
Syntax
public class className { modifier static dataType methodName(inputParameters) { // block of code to be executed } }
Example
public class ClassMethodTest { public static int findMinimum(int num1, int num2) { int minimum = num2; if (num1 < num2) minimum = num1; return minimum; } public static void main(String args[]) { int min = ClassMethodTest.findMinimum(3, 5); // call this method without an instance. System.out.println("ClassMethodTest.findMinimum(3, 5) is: " + min); } }
Output
ClassMethodTest.findMinimum(3, 5) is : 3
- Related Questions & Answers
- What are static methods in a Python class?
- Are static methods inherited in Java?
- Static import the Math Class Methods in Java
- What are static members of a Java class?
- Static methods vs Instance methods in Java
- Why static methods of parent class gets hidden in child class in java?
- Declare static variables and methods in an abstract class in Java
- Static class in Java
- What is a static class in Java?
- What are methods in Java?
- Java 8 static methods in interfaces
- Shadowing of static methods in Java
- Differences between static and non-static methods in Java
- What are the steps to read static members in a Java class?
- What are static members of a C# Class?
Advertisements