The subclass does not override the method of the parent class. Does the super of the subclass call the method of the parent class?

when the subclass does not override the method of the parent class, does the super of the subclass call the method of the parent class? Or when the non-private method of the parent class is not overridden by the subclass, does the subclass own the method but not show it?

related codes

import java.util.Date;
public  class Test extends Date{
    public static void main(String[] args) {
        new Test().test();
    }
    
    public void test(){
        System.out.println(super.getClass().getName());
    }
}

sources of topics and their own ideas

Baidu answered this question because the getclass method is a final method of the Object class, the subclass cannot be overridden, and the getclass method returns a Class object of the currently running class. Cannot understand why the runtime object that super points to is the Test class

Nov.03,2021

Of course, what you get with new Test (). Test (); is Test. The super keyword only allows you to call the members or constructors of the parent class. In fact, it mainly allows you to call the constructor of the parent class and the methods in your parent class that are overridden by you in the subclass. You can also call hidden fields (but java does not encourage this). The
object or the Test object remains the same, even if you convert the object up to Date, and then use the getClass method to get Test, because you just changed the type of reference variable pointing to the object, and the object is still the Test object. I wonder if the parent class can consider using the following code

new Test().getClass().getSuperclass();

it is completely unnecessary to add super to your code, and the method called without super is also the method of the parent class, because getClass () is not overwritten. As a matter of fact, the method of the parent class of PS: inherits from its parent class. Finally, the getClass, in the Object you found is inherited all the way because it belongs to final.


super points to the Date,super.getClass () method that inherits from the

of Object.
public final native Class<?> getClass();//Test

so what is printed is the package name of test

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b420e7-2c60e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b420e7-2c60e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?