can a static method be overridden

Answer Posted / ramandeep

Yes you can override static methods..
see the following two classes :
public class Super
{
public static void main(String args[])
{

}

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


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

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

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

Running this gives the following output :
superclass
subclass

Which explains the behaviour itself.

By overriding the static methods we are forcing them to
behave as non-static methods when used with object.
However, making a call directly to the staticy. method will
call the method belonging to that class onl

Is This Answer Correct ?    9 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What value does readline() return when it has reached the end of a file?

604


What is the relationship between local interfaces and container-managed relationships?

602


How to implement RMI in Java?

2410


What restrictions are placed on the location of a package statement within a source code file?

627


What is a tasks priority and how is it used in scheduling?

558






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

581


What is an abstract method?

598


What is TL and its use?

1999


What is ioc concept?

701


What are the purpose of introspection?

690


Can you control when passivation occurs?

606


What is the difference between a static and a non-static inner class?

602


What is the difference between the font and fontmetrics classes?

577


What are the types of scaling?

565


What modifiers may be used with an interface declaration?

567