// static methods cannot be overwritten
?
/*class super{
???? Static String name () {
???????? return "Mother";
????}
}
?
Class test02{
???? public static void Main (string[] args) {
???????? Super S3 = new super ();
???????? System.out.println (S3.name ());
????}
}
*/
?
/*
* Result : Mother
*/
?
/*
Class super{
???? Static String name () {
???????? return "Mother";
????}
}
?
Class Sub extends super{
???? String name () {
???????? return "Baby";
????}
}
?
Class test02{
???? public static void Main (string[] args) {
???????? Super S1 = new Sub ();
???????? System.out.println (S1.name ());????????
????}
}
*/
?
Result:mother
?
/*
Class super{
???? String name () {
???????? return "Mother";
????}
}
?
Class Sub extends super{
???? Static String name () {
???????? return "Baby";
????}
}
?
Class test02{
???? public static void Main (string[] args) {
???????? Super S1 = new Sub ();
???????? System.out.println (S1.name ());????????
????}
}
*/
?
Result:mother
?
class super{
???? static String name () {
???????? return"mother";
????}
}
?
class Sub extends super{
???? static String name () {
???????? return"Baby";
????}
}
?
class test02{
???? Public staticvoid main (string[] args) {
???????? Super S = new super ();
???????? System. out. println (S.name());????????
???????? Super S1 = new Sub ();
???????? /* The run-time is a pointer to The class of Sub,s1.name () should output "Baby" . But the output mother * *
???????? System. out. println (s1. Name());
???????? /*
???????? * The result is: Mother
???????? * " A static method is determined at compile time based on the class to which the method is called and the classes that the object belongs to
???????? * The instance method is determined at run time based on the class to which the object belongs " How do you understand that?
???????? */
????}
}
?
Java static methods cannot be overwritten