Hi,
I have a doubt in overriding the methods in java.
Sample program For overriding .This program executes fine.
import java.io.*;
import java.util.*;
class one
{
public void show(){
System.out.println("I am in class one-Super Class");
}
}
class two extends one
{
public void show(){
super.show();
System.out.println("The subclass two");
}
}
class ex_override
{
public static void main(String args[])throws IOException{
two obj=new two();
obj.show();
}
}
When i declared the method as static .I cannot able to implement super keyword.
For ex:A same program with static keyword.
import java.io.*;
import java.util.*;
class one
{
public static void show(){
System.out.println("I am in class one-Super Class");
}
}
class two extends one
{
public static void show(){
super.show();
System.out.println("The subclass two");
}
}
class ex_override
{
public static void main(String args[])throws IOException{
two obj=new two();
obj.show();
}
}
Error:
ex_override.java:12: non-static variable super cannot be referenced from a static context
super.show();
^
1 error
Thank you,
With Regards,
prem