can a static method be overridden

Answer Posted / vinay

Making things more clear, how static and non-static method
behaves
public class Super
{

public static void m1()
{
System.out.println("superclass static ");
}
public void m2()
{
System.out.println("superclass nonstatic ");
}
}

public class Sub extends Super
{
public static void main(String args[])
{
Super superWalaObj = new Sub();
superWalaObj.m1();
superWalaObj.m2();

Sub subWalaObj = new Sub();
subWalaObj.m1();
subWalaObj.m2();
}

public static void m1()
{
System.out.println("subclass static ");
}
public void m2()
{
System.out.println("subclass nonstatic ");
}
}


Result:
superclass static
subclass nonstatic
subclass static
subclass nonstatic

Note: The first output is not "subclass static" as with non
static methods.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different approaches to represent an inheritance hierarchy?

570


What are the different types of exception?

562


Why are my checkboxes not being set from on to off?

624


Why are component architectures useful?

559


What is the infobus?

599






Can I have an action without a form?

586


what is handle?

1839


What is glasgow?

572


What are callback interfaces?

580


the same information whether it will connect to the database or it will be used previous information?

558


what are getters and setters in Java with examples?

1276


What do you know about seam?

585


What are externizable interface?

567


What is Remote Server?

1670


Write a singleton program?

559