
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
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 Articles
- What are static methods in a Python class?
- Static import the Math Class Methods in Java
- Are static methods inherited in Java?
- Why static methods of parent class gets hidden in child class in java?
- What are static members of a Java class?
- Declare static variables and methods in an abstract class in Java
- How do I create static class data and static class methods in Python?
- Static methods vs Instance methods in Java
- What is a static class in Java?
- Use static Import for sqrt() and pow() methods in class Math in Java
- Static class in Java
- Java 8 static methods in interfaces
- What is the difference between non-static methods and abstract methods in Java?
- What is the equivalent of Java static methods in Kotlin?
- Shadowing of static methods in Java\n

Advertisements