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
What are the four corner stones of oop?
Compare java and python.
Explain about anonymous inner classes ?
What is exception handling in java?
What is empty string literal in java?
What is data type modifier?
What are the restrictions imposed on method overriding?
How to change the priority of thread or how to set the priority of thread?
Why Java doesn’t support multiple inheritance?
How can we make string upper case or lower case?
What is broken and continue statement?
What is the statements?
Explain the importance of throwable class and its methods?
Why main() method is public, static and void in java ?
Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA?