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

How a class can implement an interface?

5 Answers   SysArc,


What about abstract classes in java?

0 Answers  


What is user defined exception?

4 Answers  


Is arraylist a class in java?

0 Answers  


What do you mean by constant time complexity?

0 Answers   Amazon,






Explain the difference between an Interface and an Abstract class?

0 Answers   BirlaSoft,


What is an Exception ?

9 Answers  


Is set sorted in java?

0 Answers  


How u dubugg ur project?

1 Answers   iFlex,


How do I remove a character from a string in java?

0 Answers  


What is a finally block? Is there a case when finally will not execute?

0 Answers  


What methodology can be utilized to link to a database?

0 Answers  


Categories