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 are the four corner stones of oop?

542


Compare java and python.

575


Explain about anonymous inner classes ?

575


What is exception handling in java?

573


What is empty string literal in java?

558






What is data type modifier?

528


What are the restrictions imposed on method overriding?

550


How to change the priority of thread or how to set the priority of thread?

611


Why Java doesn’t support multiple inheritance?

631


How can we make string upper case or lower case?

595


What is broken and continue statement?

530


What is the statements?

587


Explain the importance of throwable class and its methods?

565


Why main() method is public, static and void in java ?

590


Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA?

613