hi to all,i have a question on static block.
i saved below as test.java


class test extends a
{
static {
System.out.println("test static");
}
public static void main(String []dfs)
{


}



}
class a
{
static
{
System.out.println("a static");
}
public static void main(String []asdf)
{

}

}

o/p
as static
test static

but if i change base class as test class then

class test
{
static {
System.out.println("test static");
}
public static void main(String []dfs)
{


}



}
class a extends test
{
static
{
System.out.println("a static");
}
public static void main(String []asdf)
{

}

}
o/p
test static

explain me why "a static" wasn't print in second code when
it is in derived class



hi to all,i have a question on static block. i saved below as test.java class test extends a ..

Answer / ashish

just chek again ur code

class test extends a
{
static {
System.out.println("test static");
}
public static void main(String []dfs)
{


}



}
class a
{
static
{
System.out.println("a static");
}
public static void main(String []asdf)
{

}

}

it;s genrate the o/p
a static


class test
{
static {
System.out.println("test static");
}
public static void main(String []dfs)
{


}



}
class a extends test
{
static
{
System.out.println("a static");
}
public static void main(String []asdf)
{

}

}



test static
a static


ok jst analyze ur problem thn contact me
ashish.gupta126126@gmail.com

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More Core Java Interview Questions

there are N number of matchboxes numbered 1...N.each matchbox contain various number of stick.Two player can alternatevely pick some amount of stick from the higest stick containing box . The player is condidered win if there is no stick after his move.Find the final move so that the move player win. Note:In case the number of stick is equal ,pick the stick from the higest numbered box.

0 Answers   Manhattan,


What is the difference between serialization and deserialization?

3 Answers   ABC,


1.what is the exact difference between applet and frame? 2.Do we use main method in frames?

5 Answers  


How can a class be accessed, If no access modifiers are declared?

4 Answers  


What is the difference between Integer and int?

10 Answers   Infosys,






Does collectionutils isempty check for null?

0 Answers  


Is a string literal?

0 Answers  


What is the difference between static and non-static variables?

6 Answers  


What is the difference between I ++ and ++ I in java?

0 Answers  


What is the difference between the paint() and repaint() methods in java programming?

0 Answers  


Is there a sort function in java?

0 Answers  


What is the output of the following Java program? class Main { public static void main(String args[]){ final int i; i = 10; System.out.println(i); } } 10. What is the output of the following Java program? class Main { public static void main(String args[]){ final int i; i = 10; System.out.println(i); } }

1 Answers  


Categories