What is non static block in java

Answers were Sorted based on User's Feedback



What is non static block in java..

Answer / anuradha

Any Block of code written between { and } ca be called as
non-static block in java

Is This Answer Correct ?    41 Yes 6 No

What is non static block in java..

Answer / sreenu karampudi

Non static blocks: Code within {} is non-static block
for example:

{
// code
}

Is This Answer Correct ?    28 Yes 3 No

What is non static block in java..

Answer / raj_allinterview

Non static block is a block which is surounded by { and }
for ex :

{
//code goes here
}

The code within non static block is executed whenever a new
instance of that class is created.
It is instance block.

Is This Answer Correct ?    25 Yes 2 No

What is non static block in java..

Answer / syed

class demoStaticnonstatic
{
int i;
demoStaticnonstatic()//constructor
{
System.out.println("Under Constructor");
}//end
static//static block
{
System.out.println("Under static block");
}//end
//non-static block
{
System.out.println("Under non-static
block");
}//end
public static void main(String[] args)
{
System.out.println("under main method!");
demoStaticnonstatic d=new
demoStaticnonstatic();
}
}
STATIC BLOCK: is used in real time senarios, it provide
information regording the project(name.company,version etc)
before actually project executed.
NON-STATIC BLOCK:is used for - if we have many constructor
in a application and those constructor have same statements
instead of repeate those statement in each constructor,we
place that statement in non-static block.

Is This Answer Correct ?    25 Yes 2 No

What is non static block in java..

Answer / mohan

In between {....}whatever u can write that consider as
Instance block or Non static block.

Ex:
class hai{

//Instance block
{
System.out.println("hi i'm Instance block....");
}

//Static block
static{
System.out.println("hi i'm Static block....");
}

}

Is This Answer Correct ?    8 Yes 0 No

What is non static block in java..

Answer / avneet singh bhatia

Any method which is not the part of main function or not be
declared with any static keyword is non static block in java

For example:

class Abc
{
void show()//non static method
{
System.out.println("non static block");
}
static
{
S.O.P("static");
}
}

Is This Answer Correct ?    8 Yes 4 No

What is non static block in java..

Answer / varun reddy

Non-static block is called anonymous block.the block of code which is return inside a non static block is executed on creation of object and before invoking clonstructor.
Syntax of non static block::::-------
{
statements;
}

Is This Answer Correct ?    3 Yes 0 No

What is non static block in java..

Answer / sujay

An instance block in a java program can be said to be a
non-static block. The scope of a static block is same as the
scope of that class, It will be loaded into the memory when
the class is loaded into the memory and unloaded at the time
of class unloading. But the scope of an instance
block(non-static block) is same as the scope of the object
of that class, it will be loaded into the memory when every
an objected is created and destroyed when that object is
destroyed. So, static block is created only once at the time
of class loading and globally available to all the objects
of that class where as a separate copy of instance block is
created for each object.
class MyClass
{
static
{
System.out.println("I am static, available for all
the objects of this class!");
}

{
System.out.println("I am non-static, available as a
separate copy for each object that is created from this
class!");
}
}

Is This Answer Correct ?    2 Yes 0 No

What is non static block in java..

Answer / srinivasa

Instance methods are called non static blocks. Because we
can't call them without creating the object.Constructor is
also a non static block. Non Static means other than the
static block and static methods in a class . So we ca the
above two as non static block.

Is This Answer Correct ?    4 Yes 4 No

What is non static block in java..

Answer / srinivasa

No Non Static blocks in java

Is This Answer Correct ?    13 Yes 34 No

Post New Answer

More Core Java Interview Questions

Write code of any action class?

0 Answers  


What do you mean by stack?

0 Answers   Accenture,


How can you make sure that your singleton class will always return single instance in multi-threaded environment?

0 Answers  


What is unicode with example?

0 Answers  


What is the purpose of tostring() method in java?

0 Answers  


Can you call a method on a null object?

0 Answers  


Why are there no global variables in java?

0 Answers  


How is rounding performed under integer division?

2 Answers   Satyam,


What are the types of casting?

0 Answers  


my method "abc" return array of interface "xyz" and "pqr" is abstract class implements abc and class "jkl" extends pqr My problem 1) when i call abc it retrun array xyz how can i do this hint xyz refer_xyz = new jkl(); but i can't create array. 2)I want to access method of jkl using reference of xyz??

1 Answers  


Difference between error and exception

3 Answers   Nous, TCS,


What is the difference between a choice and a list?

0 Answers  


Categories