static

How and where to use Static modifier in Java?

How and where should we use a Static modifier for: 1. Field and 2. Method? For example in java.lang.Math class, the fields methods like abs(), atan(), cos() etc are static, i.e. they can be accessed as: Math.abs() But why is it a good practice? Say, I don't keep it static and create an object of the class and access it, which anyway...

When do static variables get initialized in C#?

I was wondering about when does a static variable(in a class) come into picture(initialized)? Is it after the instance constructor called for the first time or after the class loads? When does a class loading occur? ...

C# console (static class clarification)

Hello, I hope I understood the concept of static classes (thanks to Jon Skeet and his answer on my other question). Also, I am only intersted why on MSDN they do not show Console as typical static class. Or is Console something special in this way? ...

A class that only has static data and methods to access these data. How to implement that properly?

I know that is a beginner's question. I'm new to java and and also to programming in general. Say I got a class that has only static data, example: class Foo { private static int x; } I want to use the class without instantiating any object. So I want to be able to do: Foo.setX(5); Foo.getX(); What is the best way to implement th...

Why const is undefined in static function ?

Why the name constant is not recognised in the static function f2() ? class Foo { protected static function f1($s) { echo "doing $s"; } } class Bar extends Foo { const name = 'leo'; public static function f2() { Foo::f1(name); } } $bar = new Bar(); $bar->f2(); I get the following error: Notice: Use...

How do I share data between custom Ant tasks?

I wrote two different custom Ant tasks. They are trying to share data through a static member in a base class. This is not working for me. I assume I am using static members correctly within Java. I think this is a dynamic loading issue with the Java VM. However, I am a relative newbie with Java. Since Ant custom tasks are mapped a...

Stopping orientation change with side-keyboard (Android)

I am wondering how I can make the orientation of the screen permanent, even when the phone has a slide-out keyboard. This is the code I have: <activity android:name=".AppName" android:label="@string/app_name" android:screenOrientation="portrait"> Thanks. ...

How to convert phpBB board to static archive page?

Hello! I used to run a phpBB forum for our class in school but we have now graduated and the forum isn't used anymore. I want to remove the phpBB installation but there is a lot written in the forum that is fun to read now and then. I wonder if there is an easy way to convert the phpBB forum to some kind of static archive page that any...

Simple Singleton instantiation problem

I must be doing something very silly, but I'm getting a ExceptionInInitializerError when I try to instantiate an object in my Singleton: class MySingleton { private static MySingleton instance = null; private OtherObject obj; // Do I instantiate obj here??? private MySingleton() { //obj = new OtherObject(); } // Or he...

Java static method can't compile

Hi, the following messege appears when I compile this code. ExtractChars(java.lang.String,int) in Question2 cannot be applied to () What should I fix? Thanks. import java.util.Scanner; public class Question2 { public static void main (String[] args) { ExtractChars(); } public static String ExtractCha...

iPhone static libraries

Hi, I have some problems with creating static libraries. Let say I have the static library A which I created and I included that to static library B with the relevant header files. I need to create a static library C which will be my final library and it it should include static library B which implicitly include the static library A....

What is the difference between String.Format and string.Format (and other static members of primitive data types)?

As far as I can tell, any static member of a class like String or Int32 can also be accessed from the related primitive data type. So, String.Format is the same as string.Format, and Int32.MaxValue is the same as int.MaxValue. Is there a difference between these two forms? Is one preferred to the other? Even if they are identical, is on...

PHP: Calling a class method from another class..

Hi all, basically I have two classes Inventory and Character. During the construct of the inventory I am trying to determine the characters gender however this just doesn't seem to be working for me at all.. I haven't really used static functions before so if somebody could point out what I'm doing wrong it would be much appreciated.. F...

Django Not Loading All CSS Files

I have several CSS files listed in my base.html, and while one of them is loaded, everything else isn't, nor the javascript or images. The following is a portion of base.html: <html> <head> <link href="/media/css/base.css" rel="stylesheet" type="text/css"/> <link href="/media/css/home.css" rel="stylesheet" type="text/cs...

C++ Static Property

I am having issues accessing a static property in a class. I am getting the following error: shape.obj : error LNK2001: unresolved external symbol "public: static class TCollection<class Shape *> Shape::shapes" The definition of the class is: class Shape { public: static Collection<Shape*> shapes; static void get_all_instanc...

Application structure

Hello, I have such classes: class Base { private: bool mEnabled; public: bool getEnabled() { return mEnabled; } }; class First : public Base; { // ... }; class Second : public Base { Second() { // I have to check First::mEnabled } }; class Manager { First obj1; Second obj2; }; I have some class manager...

final and static in Java

I have read this sentence in a book but I didn't understand it: A field that is both static and final has only one piece of storage that cannot be changed. Can anyone explain it for me? ...

MVVM ViewModel and static methods

Hi everybody! I try to rewrite my Application using the MVVM pattern. I have a window to show related documents for different objects with static methods like this: public partial class ShowRelatedDocuments : Window { private ShowRelatedDocuments() { InitializeComponent(); } public static void ShowRe...

C++ project compiles as static library but not dynamic (Visual Studio)

I'm a little new to c++ in visual studio, and I'm trying to compile a massive C++ project with Visual Studio. I've gone through and added all source and header files to my project and also updated all of the include paths in the project properties. If I have the type of project set to "Static Library (.Lib)" the project will compile wi...

How do static properties work in an asp.net enviroment?

If I had a class with a static property that is set when a user loads a particular page, is that static value unique to that users session? In other words, if a second user then loads the page and sets the static property, will each user have a distinct value, or will both use the second users value? ...