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

How would you create a button with rounded edges?

566


Which characters may be used as the second character of an identifier, but not as the first character of an identifier?

556


What is the map interface?

622


Where we can write Rmi registry in the code, without having to write it at the command prompt?

2272


When is the best time to validate input?

616






what are the activation groupworks?

1687


What happens when a thread cannot acquire a lock on an object?

552


Which javutil classes and interfaces support event handling?

593


What are local interfaces? Describe.

707


Is infobus easy to use?

607


What is the difference between system.out ,system.err and system.in?

606


What is the argument type of a programs main() method?

569


What class is used to create Server side object ?

1680


What is the purpose of the notifyall() method?

619


Do I need to import javlang package any time? Why ?

633