Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:22:50+00:00 2026-06-03T07:22:50+00:00

class Employee{ // salary variable is a private static variable private static double salary;

  • 0
class Employee{
 // salary  variable is a private static variable
private static double salary;

// DEPARTMENT is a constant
 public static final String DEPARTMENT = "Development";

public static void main(String args[]){
   salary = 1000;
  System.out.println(DEPARTMENT+  "  average salary:"+salary);
}
}

This java program contains a static variable. But I cannot understand the difference between public and private static variables.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:22:52+00:00Added an answer on June 3, 2026 at 7:22 am

    A public variable is accessible everywhere in the code – a private variable is only accessible within the class itself. In this case you’re using Employee.salary within the Employee class, so that’s fine.

    Note that the variable being static is a completely separate matter – and methods and classes have accessibility in the same way as variables.

    There are other levels of access available too – protected and the default “package” access (which can’t be specified explicitly). See section 6.6 of the Java Language Specification for more details.

    (As a side matter, it’s also worth learning about what static means – you almost certainly don’t want these variables to be statics, as they apply to each Employee rather than the Employee concept in general. It’s odd for DEPARTMENT to be a constant here, too.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user defined class, say import java.util.Calendar; public class Employee{ private String
Consider the following inheritance: abstract class Employee { private string empID; private string empName;
I have 3 classes, two inherit from 1: public class Employee { private virtual
I have a simple POJO like public class Employee { int level; int salary;
My Model Class as follows: public class Employee { public Guid ID { get;
This is what my data model classes look like: public class Employee { public
As a simplified example, I have the following data classes: public class Employee {
I have a class (called Employee. non static) defined in a class library. I
I have the following entity public class Employee { public int EmployeeID { get;
If I have a couple of classes like this ; public class Employee {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.