¿Qué es el método estático en OOP?
Static methods are the methods which can be accessed without creating an
object of a class.
Some times we want to define a method inside
a class that can work independently so we cab use static keyword to in start
of method to declare static method.
public class StaticDemo
{
static int a = 13;
static int b = 1199;
static void callme()
{
System.out.println("The value of a = " + a);
}
}
public class TestThis
{
public static void main(String args[])
{
//Static method is being called using the name of the class
StaticDemo.callme();
//Static variable is accessed with the class name
System.out.println("The value of b = " + StaticDemo.b);
}
}
Output:
The value of a = 13
The value of b = 1199
Dull Dingo