can a static method be overridden

Answer Posted / ravi ranjan

Yes a static method can be overridden
see following two classes

public class Test extends Test2{

public static void main(String args[]){
String str="";
int b=Test.cal(4);
System.out.println(b);
Test t =new Test();
t.displayX();
}
public static int cal(int a){
int c=a*a;
System.out.println("Hi I am Child" );
return c;
}
}

class Test2 {
public static void main(String args[]){

}

public static int cal(int a){
int c=a*a;
System.out.println(c);
return c;
}

public void displayX(){
System.out.println("HI i am in Super");
}

}

Compile this code there is no compile or run time error

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

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

602


What is clustering? What are the different algorithms used for clustering?

586


How would you detect a keypress in a jcombobox?

684


Java is fully object oriented languages or not?

552


What must a class do to implement an interface?

590






In our urls and in the text of the buttons we have comma. Its causing an error. Is there a way to change the delimiting character for the menu arguments?

594


what are the activation groupworks?

1687


Is a class a subclass of itself?

598


Why do threads block on i/o?

697


What is the relationship between the canvas class and the graphics class?

554


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

602


What do you know about seam?

606


What is the difference between RMI and Corba?

2276


What are JTA/JTS and how they used by client?

1725


Explain RMI Architecture?

621