// 静态方法不能被覆盖
?
/*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
static
void main(String[] args){
????????Super s = new Super();
????????System.out.println(s.name());????????
????????Super s1 = new Sub();
????????/*运行时是指向Sub的类,s1.name()应该输出"baby"的。却输出mother了*/
????????System.out.println(s1.name());
????????/*
???????? * 结果是:mother
???????? * "静态方法在编译时根据调用该方法的类或对象所属的类决定
???????? * 实例方法在运行时根据对象所属的类决定"该如何理解?
???????? */
????}
}
?