STATIC

STATIC

WHAT IS STATIC BLOCK?EXPLAIN , AND WHAT IS THE DIFFERENCE BETWEEN STATIC BLOCK AND STATIC METHOD?

View Answers

September 21, 2012 at 3:17 PM

A STATIC block is automatically executed the first time the class where it is defined is called.

Difference between static block and static method:

static block will execute when ever execution starts, it means this block executes first of all, where as static block have to call separately and also it can call with out object instance.

Here is an example:

public class StaticTest {

static{
System.out.println("Hello from static block");
}
public static void helloMethod()
{
System.out.println("Hello from static method");
}
public static void main(String[] args) {
helloMethod();
}
}









Related Tutorials/Questions & Answers:
STATIC
STATIC  WHAT IS STATIC BLOCK?EXPLAIN , AND WHAT IS THE DIFFERENCE BETWEEN STATIC BLOCK AND STATIC METHOD?   A STATIC block is automatically... between static block and static method: static block will execute when ever
static
Static Concept  in what are all the situation we may use static...,then use static blocks and without creation of object we need to perform some task,then go for static methods. If we want variables those values will not be changed
Advertisements
static
static  what r the main uses of static in java   Hi Friend, The Static means that a certain object/variable is resident in memory and accessed each time an instance of a class, an object, is created. When static
Static
Static  Can i know the real time example for Static method and final variables with defenition? Thank you
static
static  What is the exact need of declaring a variable as static?   A static variable is a variable who's single copy in memory is shared by all objects,so any modifications to the static variable will modify it's value
static
redeclare static variable in the inherited class  can we redeclare static variable in the inherited class like this: public class StaticClass1 { class StaticClass1{ static int noOfInstances; StaticClass1
static in java
static in java  what is the need to go static? what use
Static method
Static method  what is a static method?   Have a look at the following link: Java Static Method
static method
static method  Give some absolute examples and definition for static method also
static methods
static methods  why static methods cannot read or write the instance variables
static functions
static functions  Give some brief defenition for 1. Static Variables 2. Static Functions 3. Instance Variable  Static Variables Static...)It is a variable which belongs to the class and not to object(instance). 2)Static
static keyword
static keyword  please give some detail about Static keyword.   Static Variables Static variables are class variables that are shared... and not to object(instance). 2)Static variables are initialized only once , at the start
static keyword
static keyword  Hii, In which portion of memory static variables stored in java. Is it take memory at compile time? thanks deepak mishra
Static Variable
Static Variable  What is the basic use of introducing static variable type in java?Please explain clearly....   The Static means... of a class, an object, is created. When static is applied to member variables
Static
Static       Static... an instance of a class. Static methods are implicitly final method, since overriding depends on the type of the object, and static methods are attached to a class
static
demonstrate a) static data members b) static methods
demonstrate a) static data members b) static methods  demonstrate a) static data members b) static methods
static keyword with real example
static keyword with real example  static keyword with real examplestrong text
Java static import
Java static import  What is the use of static import
Java static method
Java static method  Can we override static methods
why using static keyword
why using static keyword  why using static keyword
About Static Class
About Static Class  is it neccessary to create object for static class
Static keyword in public static void main
Static keyword in public static void main  Hi, I have seen that on page mentioned below for static keyword explanation given is: Page: http...: static keyword indicates that this method can be invoked simply by using the name
static page and dynamic pages?
static page and dynamic pages?  what is the static page and dynamic pages adv and disadv
static variable in php
static variable in php  How can i call a global variable as a static variable
STATIC VARIABLE DECLARATION
STATIC VARIABLE DECLARATION  why cannot the static variable declare inside the method
private static final
private static final  Why there is necessary to make a variable private static final
Static & Instance variables in java
Static & Instance variables in java  What are the Difference between Static & Instance variables in java
Static Method in Java
Static Method in Java  Is Overriding Static methods possible in java? If Yes, How
static page and dynamic pages?
static page and dynamic pages?  what is the static page and dynamic pages
static page and dynamic pages?
static page and dynamic pages?  what is the diff between static page and dynamic pages
Can a class be declared as static?
Can a class be declared as static?  Hi, Can a class be declared as static? thanks
What is the importance of static variable?
What is the importance of static variable?  hi, What is the importance of static variable? thanks
Java static method example
Description: Static variable are used within the static method. Non static variable do not exits in the static method. Static variables are shared by its class instances. Static variable can be used without using the instances
ModuleNotFoundError: No module named 'static'
ModuleNotFoundError: No module named 'static'  Hi, My Python... 'static' How to remove the ModuleNotFoundError: No module named 'static'... to install padas library. You can install static python with following command
how to call static method
how to call static method  class A { //some code } class B extends class A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends class A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends class A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends A { static method() } class C { } //how to access static method() from B to C
static object array
static object array  static object array   Dynamically call a static variable array class Blog { public static $template = array('content' => 'doodle'); } Blog::$template['content'] = 'bubble'; $class = 'Blog
class static - Java Beginners
class static  When do we declare a member of a class static?  Hi friend, public class HowToAccessStaticMethod{ int i; static int j; public static void staticMethod(){ System.out.println("you can access
how to inherit static variable
how to inherit static variable   how to inherit static variable or methods in Java?? Please explain the entire process of inheriting the variable. Thanks in advance
Serialize the static variable
Serialize the static variable  hello, Can we serialize the static variable?   hiiADS_TO_REPLACE_1 Yes we can serialize the static variable. if u don't want to serialize, u need to declare the variable as transient
Static Method in PHP - PHP
Static Method in PHP  So far I can easily use the normal functions as variable in PHP? but how can use static method?  Hi Friend, Please...-static-variable-method.html Thanks
include a static file
include a static file  How will you include a static file in a JSP page?    You can include a static resource to a JSP using <jsp:directive > or <%@ inlcude >. ADS_TO_REPLACE_1
public static void main
public static void main  what is mean public static void main?  .... static-It indicates that the main() method is a class method. void- It indicates... information, visit the following link: Understanding public static void main
static & instance - Java Beginners
static & instance  what is different between static variable and instance variable .? plz explain with example. and when we can use static variable... { private static int noOfObjects; private int count; public Main
static keyword in interface
static keyword in interface  Could any one explain,why static keyword implict (or explict ) come in interface? I asked lot of persons about this question, but nobody did not answered clearly. please explain clearly and say what

Ads