answersLogoWhite

0


Best Answer

A static constructor is used to do anything you need done before any static methods are called such as static variable initialization. In Java (as in C#) when a static constructor is called is non-deterministic but will always be called before a static method on the same class.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago
JavaThere is really no such thing as a static constructor in Java. The closest thing that comes to mind is a factory class, which calls a private constructor when a static method is called.

class A {
// This private constructor can't be called by any other class.
private A() {
}

// Here is your "static" constructor
public static A getInstance() {
return new A();

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Static members are local to the class rather than to instances of the class. In other words, they are shared amongst all instances of the class. Moreover, since they are static, they exist even when no instances of the class exist. Thus static member methods and friends of the class can access static member variables and external functions can access the public static members, without instantiating an object of the class.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

No, it's not. Constructors operate with pointers when fields by default operate with values.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Static members are loaded when the class creates...while others only when an instance of that class creates...

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Difference between static and non static constructor?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What happen when static data field is initialised in a non static constructor?

It got initialized as you instructed.


Can you refer non static method from static content in java?

Shortly, you can not.Different approaches are however available.1. Put your non static method in different class. Then call it from your static content by first instantiating the class.2. Make a duplicate static method for your non static method and use from your static content.


What is the difference between static and nonstatic member with example in java?

It depends on whether the member is a static variable or a static method of the class.A non-static member variable is an instance variable. That is, each instance of the class has its own independent set of instance variables.A static member variable is not associated with any one instance of the class, and exists even when there are no instances of the class. As with all static variables, it exists for the entire duration of the program.A non-static member method is an instance method, thus the method automatically inherits a this pointer.A static member method does not inherit a this pointer, but it does have private access to to the class. Thus specific instances can be passed to a static method if necessary.Static members can be thought of as being common to all instances of a class, rather than a specific instance, even though no instances are actually required in order to make use of them.


How do you differentiate between a member function and normal function?

A normal function is any function that is not a member of any class. Normal functions that operate upon a class are referred to as non-member functions, however a non-member function can also be a member of another class. Any class may declare any non-member function to be a friend of the class, in which case the function becomes a friend function.A member function is a member of a class and may be declared static or non-static. Non-static member functions have the following 3 properties:Private access to the class members.Scoped to the class.Must be invoked against an object of the class (has a 'this' pointer).Static member functions have the first two properties only while friend functions have the first property only. Non-member functions that are not friends of the class have none of these properties.


What is cgi and non cgi sites?

difference between cgi and non cgi sites

Related questions

What happen when static data field is initialised in a non static constructor?

It got initialized as you instructed.


What is non static constructor in c sharp?

The non static constructors in C# are the ones participate in object creation, while static constructors are for loading class definitions. The latter one does not create object instance of the class being loaded Below are the example of both: public class Dummy { // static constructor, no modifier to the method static Dummy() { Console.Write("loading class Dummy"); } // the default non static constructor, in conjunction with new operator public Dummy() { Console.Write("creating an instance of Dummy"); } }


How are parametrized constructor different from non parametrized constructor?

Parameterised constructors accept arguments while non parameterised constructors do not. Example : class A { A(){ // non parameterised ... } A(int b){ // parameterised ... } }


What is the difference between a proposition and a non proposition?

difference between a proposition and non proposition


What is the difference between agriculture and non-agriculture?

Agriculture is farming and non-agriculture is non farming.


Difference between typing and non typing keys?

Difference between typing and non typing keys


What is an electrical force between non moving charges called?

The electrical force between non-moving charges is known as the electrostatic force. It is a static force that acts between stationary charged particles due to their electric fields.


Whats the difference between static and constant?

The value of a static readonly field is set at runtime; therefore, the value can be modified by the containing class. On the other hand, the value of a const field is set to a compile-time constant. In the case of static readonly, the containing class is allowed to modify the value only: * in the variable declaration (via a variable initializer) * in the static constructor (or instance constructors for non-static)Typically, static readonly is used either when the value is unknown at compile time or if the type of the field is not allowed in a const declaration. Also, instance readonly fields are allowed. Note: for reference types, in both cases-static and instance-the readonly modifier only prevents assignment of a new reference to the field. It does not specifically make the object pointed to by the reference immutable.


Is static a contact force?

No, Stactic electricity is a non-contact force!


What is constructor and discuss different types of constructor with syntax and examples?

A constructor is a class method which initialises an object of the class at the point of instantiation. Specifically, it initialises the base classes (if any) and the non-static data members (if any). Constructors also play a central role in the resource acquisition is initialisation (RAII) paradigm. Objects which have a natural default value have a default constructor. The default constructor is a constructor that has no arguments or where all arguments have default values. Objects which can be copied have a copy constructor. The copy constructor has just one non-default argument, a const l-value reference of the same type as the class. Objects which can be moved have a move constructor. The move constructor has just one non-default argument, a modifiable r-value reference of the same type as the class. All other constructors that have only one argument of a type other than the class itself are known as conversion constructors. Constructors can also have more than one argument. No specific name is given to these constructors. Other than physical memory constraints, there is no limit to the number of constructors that may be defined for a class.


What are the difference between managerial and non managerial levels?

Discuss the difference between managerial and non managerial tasks?


Difference between operational communication and non operational communicatuion?

what is difference between operatyional and non operational communication