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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain notify() method of object class ?

852


If I only change the return type, does the method become overloaded?

726


What is jvm? Why is java called the platform independent programming language?

766


What is a finally block?

757


Is null a value?

781


Is vector thread safe in java?

766


Why are pointers not secure?

779


What is difference between filereader and bufferedreader?

723


What is pre increment and post increment in java?

706


Why is string class considered immutable?

809


What do you mean by singleton class in java?

685


What methodology can be employed to locate substrings inside a string?

719


Why string objects are immutable in java?

805


Can classes declared using the abstract keyword cab be instantiated?

824


Where are variables stored?

743