Answers for "java static keyword meaning"

5

what is static keyword in java

Static keyword is used a lot in java. 
 Static means, you
can access those static variables
without creating an object,
just by using a class name.
This means that only one instance of
that static member is created which
is shared across all instances of the class.
Basically we use static keyword when
all members share same instance.
Posted by: Guest on December-05-2020
1

static keyword in java

// example on static method in java.
public class StaticMethodExample
{
   static void print()
   {
      System.out.println("in static method.");
   }
   public static void main(String[] args)
   {
      StaticMethodExample.print();
   }
}
Posted by: Guest on November-21-2020
1

static keyword in java

// example on static variable in java.
class EmployeeDetails
{
   // instance variable
   int empID;
   String empName;
   // static variable
   static String company = "FlowerBrackets";
   // EmployeeDetails constructor
   EmployeeDetails(int ID, String name)
   {
      empID = ID;
      empName = name;
   }
   void print()
   {
      System.out.println(empID + " " + empName + " " + company);
   }
}
public class StaticVariableJava
{
   public static void main(String[] args)
   {
      EmployeeDetails obj1 = new EmployeeDetails(230, "Virat");
      EmployeeDetails obj2 = new EmployeeDetails(231, "Rohit");
      obj1.print();
      obj2.print();
   }
}
Posted by: Guest on November-21-2020
1

static keyword in java

// example on static class in java.
import java.util.*;
public class OuterClass
{
   // static class
   static class NestedClass
   {
      public void show()
      {
         System.out.println("in static class");
      }
   }
   public static void main(String args[])
   {
      OuterClass.NestedClass obj = new OuterClass.NestedClass();
      obj.show();
   }
}
Posted by: Guest on November-21-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language