static in java
static keyword is a non-access modifier. static keyword can be used with
class level variable, block, method and inner class or nested class.
static in java
static keyword is a non-access modifier. static keyword can be used with
class level variable, block, method and inner class or nested class.
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();
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us