Override a Static Method.

It is possible to override a Static method. But make sure that all the methods having the same signature along with the Static keyword.

package Override;

/**
 * @author ashok.kumar
 *
 */
public class Parent 
{
	public static void printData()
	{
		System.out.println("Parent Class.");
	}
}

/**
 * 
 */
package Override;

/**
 * @author ashok.kumar
 *
 */
public class Child extends Parent{
	
	public static void printData()
	{
		System.out.println("Child Data.");
	}
	public static void main(String[] args) 
	{
		Parent obj=new Child();
		obj.printData();

	}

}
Output:
Parent Class.



698total visits,14visits today

Leave a Reply

Your email address will not be published. Required fields are marked *