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

What is return data type?

561


What is meant by inheritance and what are its advantages?

580


What is meant by call by reference?

511


What a static class can contains?

699


What is the use of using enum to declare a constant?

558






What is the difference between yielding and sleeping?

559


Write a program to print fibonacci series

613


What is difference between static and final?

561


How to reverse string in java?

617


What is the default execution method in java?

624


Is jdk required on each machine to run a java program?

755


what are the high-level thread states? : Java thread

562


Name four container classes.

559


What is a treeset in java?

547


How do you compare objects in java?

503