Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

what is static method in 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
Comment

PREVIOUS NEXT
Code Example
Java :: java selection sort 
Java :: JFrame change border 
Java :: how to code java??????????? 
Java :: Add an element to ArrayList using addall() method 
Java :: contient java 
Java :: JSONObject append 
Java :: Unable to find bundled Java version mac m1 
Java :: check if input is empty java 
Java :: jhow to check if a string is a punctuation java 
Java :: expression régulière téléphone java 
Java :: difference between two sets java 
Java :: final method and abstract method 
Java :: miles to km converter programm in java 
Java :: can the method local inner class object access method local variables 
Java :: copy text from header tag in javacript 
Java :: hashmap put method 
Java :: refreshing method() android studio webview 
Java :: greatest of three in java 
Java :: java user home directory macos 
Java :: garbage collection in java 
Java :: convert alphabet to number in java 
Java :: JAVA Multi-line Comment 
Java :: syntax of the switch statement in Java 
Java :: what is ioexception in java 
Java :: Implementing the LinkedList Class in java list 
Java :: loops in java 
Java :: Java char Keyword 
Java :: how to initialize a variable in java 
Java :: java put() method 
Java :: minecraft addlayer(u) in the type rendererlivingentity<t is not applicable for the arguments 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =