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
Explain notify() method of object class ?
If I only change the return type, does the method become overloaded?
What is jvm? Why is java called the platform independent programming language?
What is a finally block?
Is null a value?
Is vector thread safe in java?
Why are pointers not secure?
What is difference between filereader and bufferedreader?
What is pre increment and post increment in java?
Why is string class considered immutable?
What do you mean by singleton class in java?
What methodology can be employed to locate substrings inside a string?
Why string objects are immutable in java?
Can classes declared using the abstract keyword cab be instantiated?
Where are variables stored?