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
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 |
How is object created in java?
When arithmeticexception is thrown?
What is arraylist e in java?
Can we extend the String class?
Can final class have constructor?
What is JFC?
Can an interface extend another interface?
Is map ordered in java?
Do we need to manually write Copy Constructor?
What are the traverses in Binary Tree?
What is the difference between static and global variables and also define what are volatile variables?
0 Answers Flextronics, Hexaware,
What is difference between add() and addelement() in vector?