Hi,
Static methods cannot be overriden right!!!Please read the following program.
Question:
class TestSuperClass{
static
String s1="Super S1";
String s2="Super S2";
static void printS1(){
System.out.println(s1);
}
void printS2(){
System.out.println(s2);
}
void printBoth(){
printS1();
printS2();
}
}
class TestSubClass extends TestSuperClass{
static String s1="Sub S1";
String s2="Sub S2";
static void printS1(){
System.out.println(s1);
}
void printS2(){
System.out.println(s2);
}
public static void main(String args[]){
new TestSubClass().printBoth();
}
}
Answer is :Super S1 Sub S2.
How is it possible?whether static methods can be inherited?
Thanks in Advance.