Don’t understand static boolean behavior

static in this context means “local” (to the translation unit). There will be multiple copies of read_mess in your program, one per translation unit which is not the same thing as a header file. (In your case you can most likely approximate “translation unit” as .cpp or .c or .cc file). Probably what you meant to do was to declare an extern variable, or static class … Read more

What is the use of a private static variable in Java?

Of course it can be accessed as ClassName.var_name, but only from inside the class in which it is defined – that’s because it is defined as private. public static or private static variables are often used for constants. For example, many people don’t like to “hard-code” constants in their code; they like to make a public static or private static variable with a meaningful … Read more

Static Semantics meaning?

Semantics is about meaning. It includes: the static semantics, which is the part that can be ascertained at compile time, including data typing, whether all variables are declared, which declaration applies to which variable in the case of scoping, what their type is, whether functions and methods are called with correct calling sequences, whether assignments … Read more

Static Block in Java

It’s a static initializer. It’s executed when the class is loaded (or initialized, to be precise, but you usually don’t notice the difference). It can be thought of as a “class constructor”. Note that there are also instance initializers, which look the same, except that they don’t have the static keyword. Those are run in addition to the code in the constructor … Read more

Difference between static class and singleton pattern?

What makes you say that either a singleton or a static method isn’t thread-safe? Usually both should be implemented to be thread-safe. The big difference between a singleton and a bunch of static methods is that singletons can implement interfaces (or derive from useful base classes, although that’s less common, in my experience), so you can pass … Read more

Difference between Static methods and Instance methods

The basic paradigm in Java is that you write classes, and that those classes are instantiated. Instantiated objects (an instance of a class) have attributes associated with them (member variables) that affect their behavior; when the instance has its method executed it will refer to these variables. However, all objects of a particular type might … Read more

hat does “static” mean in C?

A static variable inside a function keeps its value between invocations. A static global variable or a function is “seen” only in the file it’s declared in (1) is the more foreign topic if you’re a newbie, so here’s an example: This prints: This is useful for cases where a function needs to keep some … Read more

Static array vs. dynamic array in C++

Local arrays are created on the stack, and have automatic storage duration — you don’t need to manually manage memory, but they get destroyed when the function they’re in ends. They necessarily have a fixed size: Arrays created with operator new[] have dynamic storage duration and are stored on the heap (technically the “free store”). They can … Read more