ashish


{ City } aligarh
< Country > india
* Profession * employee
User No # 57850
Total Questions Posted # 0
Total Answers Posted # 1

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 0
Users Marked my Answers as Wrong # 2
Questions / { ashish }
Questions Answers Category Views Company eMail




Answers / { ashish }

Question { 2894 }

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

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